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

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
;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1554 views
  • 1 like
  • 3 in conversation