BookmarkSubscribeRSS Feed
b384b7
Calcite | Level 5
data user_format;
input ID : $3. gender$ age salary (ques1-ques5);
datalines;
  001 M 23 28000 1 2 1 2 3
  002 F 55 76123 4 5 2 1 1
  003 M 38 36500 2 2 2 2 1
  004 F 67 128000 5 3 2 2 4
  005 M 22 23060 3 3 3 4 2
  006 M 63 90000 2 3 5 4 3
  007 F 45 76100 5 3 4 3 3 
run;
  
  proc format;
   value $gender 'M' = 'Male'
                 'F' = 'Female'
                 ' ' = 'Not entered'
                 other = 'Miscoded';
   value age  low-29 = 'Less than 29'
                    30-50 = '30 to 50'
                    51-high = '51+';
   value ques '1' = 'Strongly disagree'
                     '2' = 'Disagree'
                     '3' = 'No opinion'
                     '4' = 'Agree'
                     '5' = 'Strongly agree';
 proc print data=user_format;
 id ID;
 var gender age ques1-ques5;
 format gender $gender.
        age age.
        ques1-ques5 ques.;
 run;

sas.png

2 REPLIES 2
Reeza
Super User

You created the format with the character one, '1', not the numeric value 1, 1 (no quotes). Remove the quotes and it should be fine.

 

   value ques '1' = 'Strongly disagree'
                     '2' = 'Disagree'
                     '3' = 'No opinion'
                     '4' = 'Agree'
                     '5' = 'Strongly agree';

 

 


@b384b7 wrote:
data user_format;
input ID : $3. gender$ age salary (ques1-ques5);
datalines;
  001 M 23 28000 1 2 1 2 3
  002 F 55 76123 4 5 2 1 1
  003 M 38 36500 2 2 2 2 1
  004 F 67 128000 5 3 2 2 4
  005 M 22 23060 3 3 3 4 2
  006 M 63 90000 2 3 5 4 3
  007 F 45 76100 5 3 4 3 3 
run;
  
  proc format;
   value $gender 'M' = 'Male'
                 'F' = 'Female'
                 ' ' = 'Not entered'
                 other = 'Miscoded';
   value age  low-29 = 'Less than 29'
                    30-50 = '30 to 50'
                    51-high = '51+';
   value ques '1' = 'Strongly disagree'
                     '2' = 'Disagree'
                     '3' = 'No opinion'
                     '4' = 'Agree'
                     '5' = 'Strongly agree';
 proc print data=user_format;
 id ID;
 var gender age ques1-ques5;
 format gender $gender.
        age age.
        ques1-ques5 ques.;
 run;

sas.png


 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 905 views
  • 0 likes
  • 2 in conversation