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;
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: