BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Picketoaks
Fluorite | Level 6

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

6 REPLIES 6
paulkaefer
Lapis Lazuli | Level 10

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.

Picketoaks
Fluorite | Level 6

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

Reeza
Super User

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. 

Picketoaks
Fluorite | Level 6

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.

Picketoaks
Fluorite | Level 6

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.

Picketoaks
Fluorite | Level 6

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 6 replies
  • 1183 views
  • 2 likes
  • 3 in conversation