- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content