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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.