if gender = 'F';If gender = 'F' is true, the observation is kept in the dataset. If gender = 'F' is false, the observation is deleted.
* Converting from character to numeric; val = s + 0; val = s * 1; val = input(s, 6.2); *<-- 6.2 is an informat; * Converting from numeric to character; str = x || ""; str = put(x, 6.2); *<-- 6.2 is a format;
data states; infile "c:/datasets/states2.txt"; length state $ 14; input state $ &;
IB3. DATE. ANYDTDTE. JULIAN.IB3. reads a 3 byte integer binary field.
Special SAS Constants | |
---|---|
Example | Description |
'25dec2012'd | Date |
'25dec2012:3:45:12pm'dt | Date Time |
'3:45:12pm't | Time |
'09'x (tab) '0c'x (form feed) | Hex Character |
data combined; if _n_ = 1 then set summary; set original;
kidsa kidsb stacked ============ ============ ============= 3 Tom M 13 2 Scott M 9 3 Tom M 13 7 Sue F 11 + 6 Eve F 11 = 7 Sue F 11 9 Will M 9 8 Jane F 7 9 Will M 9 11 Jen F 8 11 Jen F 8 2 Scott M 9 6 Eve F 11 8 Jane F 7Use these statements to stack two datasets:
data stacked; set kidsa kidsb;The builtin logical in variables can be used to identify the source of each line in the resulting stacked dataset:
data stacked; set kidsa (in=a) kidsb (in=b); if a then source='kidsa'; if b then source='kidsb';See the Union Example that shows the result of stacking and interleaving two datasets.
kidsa kidsb interleaved ============ ============ ============= 3 Tom M 13 2 Scott M 9 2 Scott M 9 7 Sue F 11 + 6 Eve F 11 = 3 Tom M 13 9 Will M 9 8 Jane F 7 6 Eve F 11 11 Jen F 8 7 Sue F 11 8 Jane F 7 9 Will M 9 11 Jen F 8Use these statements to interleave two datasets. The two datasets must be sorted by the by variable for this to work.
data stacked; set kidsa kidsb; by number;See the Union Example that shows the result of stacking and interleaving two datasets.
kids teachers match_merge ============ ========= =========== 1 Tom M 45 1 Tom M 45 Patel 2 Sue F 45 45 Patel 2 Sue F 45 Patel 3 Jen F 67 + 67 Chen = 3 Jen F 67 Chen 4 Scott M 93 93 Suarez 4 Scott M 93 Suarez 5 Eve F 93 5 Eve F 93 Suarez 6 Jane F 93 6 Jane F 93 SuarezUse these statements to form the join of two datasets. This is called a match merge in SAS. Again, the two datasets must be sorted by the join variable for the match merge to work.
data merged; merge kids teachers; by teacher_number;See the MatchMerge Example.
data usa.illinois;
set usa.illinois;
array exam (7) q1 a2 a3 a4 a5 midterm final; do i = 1 to 7; if exam(i) = . then exam(i) = 0; end;
ID name,gender,age phone 11111111112222222222333 12345678901234567890123456789012 3333 James,M,13 222/333-4444 4444 Elizabeth,F,11 555/666-7777 Ans: data test; infile "c:/datasets/data.txt" firstobs=4; input id 1-4 info $ 6-19 phone $ 21-32; name = scan(info, 1, ","); gender = scan(info, 2, ","); age = input(scan(info, 3, ","), 2.);
proc contents data=sashelp._all_;
* Typewriter Graphics; proc plot; plot son*father; * SAS/Graph; proc gplot; plot son*father; * ODS Graphics; proc sgplot; scatter x=father y=son;
symbol1 value=star height=0.5 cm color=red interpol=none
goptions reset=all; goptions hsize=5 vsize=6 colors=(maroon navy black) csymbol=purple border ctitle=green interpol=needle;
goptions reset=symbol;This statement resets only options that apply to plotting symbols.
data states; infile "c:/datasets/states2.txt" truncover; input name $ &; proc print;