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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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