DATA Step, Macro, Functions and more

Trying to understand how to use Proc Format

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Trying to understand how to use Proc Format

Hi,

 

I'm reading my data and then trying to use Proc Format.  When I use Proc Print the initial values are not formatted.  After reading some explanations I'm not sure why and need a bit of help.  Thank you.

 

data mydata;
    INFILE mysource dlm=',' missover;
    input Site : $1.
             Pt : $2.
             Sex
             Race
             Dosedate : mmddyy10. 
             Height
             Weight
            Result1
            Result2
            Result3;

run;

 

proc format;
  value Sex
      1 = 'Female'
      2 = 'Male';
  value Race
      1 = 'Asian'
      2 = 'Black'
      3 = 'Caucasian'
      4 = 'other';

run;

 

proc print data=mydata;

run;


Accepted Solutions
Solution
‎07-14-2016 12:49 PM
Super User
Posts: 17,963

Re: Trying to understand how to use Proc Format

You created a format, you never applied it. 

 

Proc print data=mydata;
Format sex sex. Race race.;
Run;

This would only apply to the proc print however. You may want to change the order, put the proc format before the data import step and add the format statement to your data step. 

View solution in original post


All Replies
Regular Contributor
Posts: 161

Re: Trying to understand how to use Proc Format

You'll want to call PROC FORMAT to create the formats before the data step. Then use them like other formats (Race Race., for example; like you might call Date monyy7.) in the data step.

Occasional Contributor
Posts: 12

Re: Trying to understand how to use Proc Format

Thanks... please see my next commet to Reeza.

Solution
‎07-14-2016 12:49 PM
Super User
Posts: 17,963

Re: Trying to understand how to use Proc Format

You created a format, you never applied it. 

 

Proc print data=mydata;
Format sex sex. Race race.;
Run;

This would only apply to the proc print however. You may want to change the order, put the proc format before the data import step and add the format statement to your data step. 

Occasional Contributor
Posts: 12

Re: Trying to understand how to use Proc Format

Hi,

 

I moved the proc format to the top before the data step and ran the proc print using the format statement as suggested and to keep it simple for now... but it doesn't appear to affect the values.

 

Thank you.

Occasional Contributor
Posts: 12

Re: Trying to understand how to use Proc Format

I noticed these notes in the log if it matters:

 

30 proc format;
31 value Sex
32 1 = 'Female'
33 2 = 'Male';
NOTE: Format SEX is already on the library WORK.FORMATS.
NOTE: Format SEX has been output.
34 value Race
35 1 = 'Asian'
36 2 = 'Black'
37 3 = 'Caucasian'
38 4 = 'other';
NOTE: Format RACE is already on the library WORK.FORMATS.
NOTE: Format RACE has been output.

Occasional Contributor
Posts: 12

Re: Trying to understand how to use Proc Format

sorry for the bother... i didn't see the '.' after the format name but everything works now.  Thank you!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 305 views
  • 2 likes
  • 3 in conversation