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;

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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