BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
nayab_shaik
Calcite | Level 5

Hi team,

data demo;

input subid$ a1-a5;

cards;

101 2 1 2 1 0

102 3 1 2 0 1

103 4 2 0 2 3

104 5 0 2 0 2

105 0 1 1 1 4

;

run;

0=missing 1=mild 2=modarate 3=severe 4=life threting 5 =death

use a1-a5 variable and create same vars ac1-ac-5 replace the above formate value

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

Hi @nayab_shaik 

 

Instead of using an IF/THEN/ELSE approach to assign each value, I suggest that you define a format using a PROC FORMAT, which is easier to maintain. Then you can use a PUT() function to convert the numeric value to a character one using this format.

Arrays allow you not to repeat the same data manipulation for each variable.

NB: the array referencing the new variables (_ac, which contains ac1 to ac5) is defined as character ($). Don't forget to assign the proper length to avoid truncation (here, I have put 20).

Best,

data demo;
input subid$ a1-a5;
cards;
101 2 1 2 1 0
102 3 1 2 0 1
103 4 2 0 2 3
104 5 0 2 0 2
105 0 1 1 1 4
;
run;

proc format;
	value fa 0="missing"
			 1="mild"
			 2="moderate" 
			 3="severe" 
			 4="life threatening" 
			 5 ="death";
run;

data want;
	set demo;
	array _a (*) a1-a5;
	array _ac (*) $20 ac1-ac5;
	do i=1 to dim(_a);
		_ac(i) = put(_a(i), fa.);
	end;
	drop i;
run;

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

PLEASE USE A DESCRIPTIVE SUBJECT LINE!

(using just "sas" in the SAS Communities is not an indicator of sufficient intelligence needed to work with SAS)

And show us an example of the expected outcome; right now, your question is very hard to understand.

ChrisNZ
Tourmaline | Level 20

@Kurt_Bremser  Easily the most unhelpful title one could find. It think it will be hard to top! 🙂

Changed to: Assign categories

ed_sas_member
Meteorite | Level 14

Hi @nayab_shaik 

 

Instead of using an IF/THEN/ELSE approach to assign each value, I suggest that you define a format using a PROC FORMAT, which is easier to maintain. Then you can use a PUT() function to convert the numeric value to a character one using this format.

Arrays allow you not to repeat the same data manipulation for each variable.

NB: the array referencing the new variables (_ac, which contains ac1 to ac5) is defined as character ($). Don't forget to assign the proper length to avoid truncation (here, I have put 20).

Best,

data demo;
input subid$ a1-a5;
cards;
101 2 1 2 1 0
102 3 1 2 0 1
103 4 2 0 2 3
104 5 0 2 0 2
105 0 1 1 1 4
;
run;

proc format;
	value fa 0="missing"
			 1="mild"
			 2="moderate" 
			 3="severe" 
			 4="life threatening" 
			 5 ="death";
run;

data want;
	set demo;
	array _a (*) a1-a5;
	array _ac (*) $20 ac1-ac5;
	do i=1 to dim(_a);
		_ac(i) = put(_a(i), fa.);
	end;
	drop i;
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
  • 3 replies
  • 459 views
  • 1 like
  • 4 in conversation