I have a dataset with the question, answer coded in numeric and its categorical value. I have a lot of questions and answer choices, so I prefer not copying and pasting everything.Is there an easier way to create formats based on existing dataset like below?
data have;
input id question $ 5. ansN ansC $ 20.;
cards;
1 Q1 1 Agree
2 Q1 1 Agree
3 Q1 2 Disagree
4 Q1 2 Disagree
5 Q1 3 Refuse to Answer
1 Q2 2 BBBBBBB
2 Q2 1 AAAAAAAA
3 Q2 1 AAAAAAAA
4 Q2 3 CCCCCCCCCCC
5 Q2 3 CCCCCCCCCCC
;
The only trouble you will have is that you need to make a name for the format that does not end in a digit.
I have seen people just consistently add the letter F to the end of the name from their external metadata to make sure that the name of the format ends in a letter.
proc sort data=have(keep=question ansn arnsc)
out=codes nodupkey
;
by quesiton ansn ansc ;
run;
data cntlin;
set codes;
fmtname=cats(question,'F');
rename ansN = start ansC=label;
keep fmtname start label;
run;
proc format cntlin=cntlin;
run;
Use PROC FORMAT with the CNTLIN= option.
The only trouble you will have is that you need to make a name for the format that does not end in a digit.
I have seen people just consistently add the letter F to the end of the name from their external metadata to make sure that the name of the format ends in a letter.
proc sort data=have(keep=question ansn arnsc)
out=codes nodupkey
;
by quesiton ansn ansc ;
run;
data cntlin;
set codes;
fmtname=cats(question,'F');
rename ansN = start ansC=label;
keep fmtname start label;
run;
proc format cntlin=cntlin;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.