BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Marcus_wong
Calcite | Level 5

Hi everyone - a bit newer to SAS and running into a problem trying to adapt someone's older code.

Essentially I have a character variable with responses, and am coding in skips to it.

  • e.g. Add skip coded 777 into the open text variable OPENTEXT1 if responses are blank
  • OPENTEXT1 has character responses maxing out at 161 characters, proc contents show format=161 informat=$161.
  • Check responses with proc freq, all 777 and responses are normal

Then I create a "label" using the proc format function with value to label the skip and keep responses

  • proc format; value OPENTEXT '777'="Skip"; run;
  • data dataset1; set dataset; format OPENTEXT $OPENTEXT.
  • proc freq, this time 777 show "SKIP" but other responses truncated to 4 characters

I checked proc contents, and it is still showing format and informat still remaining at the same length.

Any help appreciated

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If you don't define a DEFAULT width for the format then PROC FORMAT will GUESS that you wanted the default to be the maximum width of all of the display values you mentioned when defining the format.  

 

You can specify the width when you use the format.

 format OPENTEXT $OPENTEXT20.;

Note that if you don't specify the maximum width it will default to 40 , unless the longest label width is more than 40.

 

Say your variable named OPENTEXT has a length of 80 then you when you define the format you will want to set the maximum width to at least 80.  But you might want to set the default to something shorter.

 

Note that character format names start with a $.

proc format; 
value $OPENTEXT (default=40 max=80)
  '777'="Skip"
; 
run;

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

If you don't define a DEFAULT width for the format then PROC FORMAT will GUESS that you wanted the default to be the maximum width of all of the display values you mentioned when defining the format.  

 

You can specify the width when you use the format.

 format OPENTEXT $OPENTEXT20.;

Note that if you don't specify the maximum width it will default to 40 , unless the longest label width is more than 40.

 

Say your variable named OPENTEXT has a length of 80 then you when you define the format you will want to set the maximum width to at least 80.  But you might want to set the default to something shorter.

 

Note that character format names start with a $.

proc format; 
value $OPENTEXT (default=40 max=80)
  '777'="Skip"
; 
run;

 

Marcus_wong
Calcite | Level 5
Thank you! After defining both in the "format" and the "proc format" with my required widths, it worked.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 851 views
  • 1 like
  • 2 in conversation