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
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;
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.
@Kurt_Bremser Easily the most unhelpful title one could find. It think it will be hard to top! 🙂
Changed to: Assign categories
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.