BookmarkSubscribeRSS Feed
valerieyim
Fluorite | Level 6

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.This is how my output look like. I would like to change Mon to 1, Tue to 2 and Wed to 3.

Thanks,

Valerie

1 REPLY 1
Kurt_Bremser
Super User

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;
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 609 views
  • 2 likes
  • 2 in conversation