Hello SAS community,
I have variables with the following
original format
proc format;
value s
0 ="Never/almost Never"
1 ="Once in a while"
2 ="Some days"
3 ="Most days"
4 ="Everyday"
5 ="Many times/day"
. ="Unknown";
I'm now being asked to do reverse formatting for a bunch of variables
/*1 = many times a day, 2 = every day, 3 = most days, 4 = some days, 5 = once in a while, 6 = never*/
data have;
input id strngth peace beauty prscnc union love;
cards;
1 0 1 2 3 4 5
2 4 0 0 1 3 4
3 4 2 3 2 5 0
4 2 4 4 0 2 3
5 0 3 5 0 0 1
6 3 5 1 4 3 4
7 5 2 3 2 1 0
8 3 2 2 5 2 1
9 5 1 3 2 1 0
10 4 0 0 1 3 4
11 0 2 3 2 5 0
12 2 4 4 0 2 3
;
run;
data have2;
set have;
format strngth peace beauty prscnc union love s.;
run;
proc freq data=have2;
title 'orig';
tables strngth / list missing;
run;
proc format;
value sr
6 ="Never/almost Never"
5 ="Once in a while"
4 ="Some days"
3 ="Most days"
2 ="Everyday"
1 ="Many times/day"
. ="Unknown";
run;
data want;
set have2;
if strngth = 5 then strngth2 = 1; else
if strngth = 4 then strngth2 = 2; else
if strngth = 3 then strngth2 = 3; else
if strngth = 2 then strngth2 = 4; else
if strngth = 1 then strngth2 = 5; else
if strngth = 0 then strngth2 = 6; else
strngth2 = .;
format strngth2 sr.;
run;
but I'm getting the following for recoded - unable to copy in both tables:
original
strngth |
Frequency |
Percent |
Cumulative |
Cumulative |
Never/almost Never |
3 |
25.00 |
3 |
25.00 |
Some days |
2 |
16.67 |
5 |
41.67 |
Most days |
2 |
16.67 |
7 |
58.33 |
Everyday |
3 |
25.00 |
10 |
83.33 |
Many times/day |
2 |
16.67 |
12 |
100.00 |
recoded
strngth2 |
Frequency |
Percent |
Cumulative |
Cumulative |
Many times/day |
2 |
16.67 |
2 |
16.67 |
Everyday |
3 |
25.00 |
5 |
41.67 |
Most days |
2 |
16.67 |
7 |
58.33 |
Some days |
2 |
16.67 |
9 |
75.00 |
Never/almost Never |
3 |
25.00 |
12 |
100.00 |
I would like to be able to-
Thanks,
Maggie
ignore my question, I now see the answer
@urban58 wrote:
ignore my question, I now see the answer
What was the solution?
Either attach the right format to the right variable.
Or recode the variable. For your variable it looks a simple subtraction should do the recoding.
peace2 = 6 - peace;
format peace2 s. peace sr. ;
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.