Documente Academic
Documente Profesional
Documente Cultură
For example
TOTAL=SUM(TIMEl,TIME2,TIME3,TIME4);
NOW=TODAY();
X1 = 1; X2 = 2; X3 = 13; X4=10;
Then
ROWS Transpose
COLUMNS
DATA SUBJECTS;
INPUT SUB1 $ SUB2 $ SUB3 $ SUB4 $;
DATALINES;
12 21 13 14
13 21 12 14 Notice how the data are not in a
desired form. Use PROC TRANSPOSE
15 31 23 23 to “flip” the data.
15 33 21 32
M F F M
;
RUN;
DATA SUBJECTS;
INPUT LAB $ SUB1 $ SUB2 $ SUB3 $ SUB4 $;
DATALINES;
BASELINE 12 21 13 14
TIME1 13 21 12 14
TIME2 15 31 23 23
TIME3 15 33 21 32
GENDER M F F M
;
PROC TRANSPOSE
DATA="C:\SASDATA\COMPLICATIONS"
OUT=COMP_OUT The PREFIX allows you to name the
combined variable.
PREFIX=COMP;
The BY variable identifies the key
BY SUBJECT;
variable to expand on.
VAR COMPLICATION;
RUN;
The VAR identifies which variables
to expand.
27 SAS ESSENTIALS -- Elliott & Woodward
HANDS ON EXERCISE P 143 (DTRANSPOSE2.SAS)
Run the code.
IF FIND(UPCASE(CCAT),"RENAL") NE 0 then
RENALFAILURE="Yes";
ELSE RENALFAILURE="No";
RUN; Use FIND() to find any instance of
PROC FREQ DATA=RENAL; “RENAL” in CCAT, and create a new
TABLES RENALFAILURE;RUN; variable named RENALFAILURE
IF FIND(UPCASE(CCAT),"RENAL") NE 0 then
RENALFAILURE="Yes";
ELSE RENALFAILURE="No";
RUN;
PROC FREQ DATA=RENAL;
TABLES RENALFAILURE;RUN;
EXERCISE – Enter and run the new code and observe results.
PAUSE – Return once you’ve completed this exercise.
END;
36 SAS ESSENTIALS -- Elliott & Woodward
Without a Specific Select Expression
Another way to use SELECT is without a specific select-
expression. In this case, the WHEN statements include
conctitional expressions that should be in parentheses.
For example:
Note in this version there is no specified comparison
variables. Comparisons are specified in the WHEN
statements.
SELECT;
WHEN (GP='A') STATUS2=1;
WHEN (GP='B' and SEX=1) STATUS2=2;
WHEN (GP='C ' and SEX=0) STATUS2=3;
OTHERWISE STATUS2=0; Use this version of SELECT
END; when comparisons are more
complex (and not just equal.)
LABEL statement
Eliminate bad
entries in
HOW_ARRIVED
Out of range
values for
AGEN
DATEARRIVED2=INPUT(TRIM(DATEARRIVED),MMDDYYl0.);
TIMEARRIVE=SUBSTR(TIMEARRIVE, l ,I-1);
Also, determine if there is a “P”
in the value – which implies that
it is PM. If P=0 then it is AM.
P=FIND(TIMEARRIVE,"P");
TIMEARRIVET=INPUT(TRIM(TIMEARRIVE2),TIME8.);
If the time is after noon, add 12 hours of seconds to the value…
(P>0 means that this time in in the PM (afternoon.))
ARRIVEDT=DHMS(DATEARRIVED2,0,0,TIMEARRIVET);
Label ARRIVEDT="Date & Time Arrived";
66 SAS ESSENTIALS -- Elliott & Woodward
DO HANDS ON EXAMPLE P 156
Open MESSY5.SAS to do correct datetime variables.
STAYHOURS=ROUND(STAYMINUTES/60,.1);
IF STAYHOURS<0 or
STAYHOURS>48 then
STAYHOURS=.;
These slides are provided for you to use to teach SAS using this book. Feel free to
modify them for your own needs. Please send comments about errors in the slides
(or suggestions for improvements) to acelliott@smu.edu. Thanks.