Hi SAS Communities,
By the end of my data, in the variable of Day, I would like to change Mon to 1, Tue to 2, and Wed to 3. Do you mind telling me what I can code to change it? I tried to use If/Else if statement but it doesn't work.
Here is my code.
DATA WORK.SwimLong2;
SET WORK.SwimMinutes;
KEEP Name Age Day Minutes;
ARRAY Date {3} $3 _TEMPORARY_ ('Mon', 'Tue', 'Wed');
ARRAY Time {3} Mon -- Wed;
DO i = 1 TO DIM(Time);
Day = Date{i};
Minutes = Time{i};
OUTPUT WORK.SwimLong2;
END;
RUN;
PROC PRINT DATA = WORK.SwimLong2;
RUN;
This is how my output look like. I would like to change Mon to 1, Tue to 2 and Wed to 3.
Thanks,
Valerie
Thanks for posting a nice example dataset.
Do the transposition from wide to long with PROC TRANSPOSE, and use an informat for the conversion:
proc transpose
data=swimminutes
out=long (rename=(col1=minutes))
;
by name age;
var mon--wed;
run;
proc format;
invalue myweekday
"Mon" = 1
"Tue" = 2
"Wed" = 3
;
run;
data want;
set long;
day = input(_name_,myweekday.);
drop _name_;
run;
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.