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

Hello, 

 

my understanding about FORMAT in SAS is if you add the format statement in DATA step, it creates permanent format. If the format statement is added to PROC print step, it only creates the format on the output.  However, when I write the following programs, the format for the variable" HireDate" didn't change, it still appears as SAS data value.  But when I move the format statement to PROC PRINT step, it shows correctly.  Why is that?  Did I miss anything?  Thanks for your help.

 

data work.sales;
infile datalines dlm="/";
input ID First :$12. Last :$12. Gender $ Salary:comma. Title :$25. HireDate :date.;
datalines;
120102/Tom/Zhou/M/108,255/Sales Manager/01Jun1993
120103/Wilson/Dawes/M/87,975/Sales Manager/01Jan1978
120261/Harry/Highpoint/M/243,190/Chief Sales Officer/01Aug1991
121143/Louis/Favaron/M/95,090/Senior Sales Manager/01Jul2001
121144/Renee/Capachietti/F/83,505/Sales Manager/01Nov1995
121145/Dennis/Lansberry/M/84,260/Sales Manager/01Apr1980
;
format HireDate mmddyy10.;
run;

Title "Orion Star Management Team";
proc print data=work.sales;
run;
Title;

Capture.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
LaurieF
Barite | Level 11

Try it like this:

data work.sales;
infile datalines dlm="/";
input ID First :$12. Last :$12. Gender $ Salary:comma. Title :$25. HireDate :date.;
format HireDate mmddyy10.;
datalines;
120102/Tom/Zhou/M/108,255/Sales Manager/01Jun1993
120103/Wilson/Dawes/M/87,975/Sales Manager/01Jan1978
120261/Harry/Highpoint/M/243,190/Chief Sales Officer/01Aug1991
121143/Louis/Favaron/M/95,090/Senior Sales Manager/01Jul2001
121144/Renee/Capachietti/F/83,505/Sales Manager/01Nov1995
121145/Dennis/Lansberry/M/84,260/Sales Manager/01Apr1980
;
run;
Title "Orion Star Management Team";
proc print data=work.sales;
run;
Title;

When you use 'cards' or 'datelines', it should be the last command in a data step. Your code as it was was reporting an error.

View solution in original post

7 REPLIES 7
LaurieF
Barite | Level 11

Try it like this:

data work.sales;
infile datalines dlm="/";
input ID First :$12. Last :$12. Gender $ Salary:comma. Title :$25. HireDate :date.;
format HireDate mmddyy10.;
datalines;
120102/Tom/Zhou/M/108,255/Sales Manager/01Jun1993
120103/Wilson/Dawes/M/87,975/Sales Manager/01Jan1978
120261/Harry/Highpoint/M/243,190/Chief Sales Officer/01Aug1991
121143/Louis/Favaron/M/95,090/Senior Sales Manager/01Jul2001
121144/Renee/Capachietti/F/83,505/Sales Manager/01Nov1995
121145/Dennis/Lansberry/M/84,260/Sales Manager/01Apr1980
;
run;
Title "Orion Star Management Team";
proc print data=work.sales;
run;
Title;

When you use 'cards' or 'datelines', it should be the last command in a data step. Your code as it was was reporting an error.

Fiery
Obsidian | Level 7

Hi Laurie, 

 

Thanks for your help!  🙂 

 

Fiery 

Tom
Super User Tom
Super User

If you want the FORMAT statement to be part of the data step then include it in the data step, not after it. You cannot have any statements for the data step after the in-line data lines.  You should have gotten an error message like this in the LOG. 

112  ;
113  format HireDate mmddyy10.;
     ------
     180

ERROR 180-322: Statement is not valid or it is used out of proper order.

114  run;

Like this:

data work.sales;
  infile datalines dlm="/";
  input ID First :$12. Last :$12. Gender $ Salary:comma. Title :$25. HireDate :date.;
  format HireDate mmddyy10.;
datalines;
120102/Tom/Zhou/M/108,255/Sales Manager/01Jun1993
120103/Wilson/Dawes/M/87,975/Sales Manager/01Jan1978
120261/Harry/Highpoint/M/243,190/Chief Sales Officer/01Aug1991
121143/Louis/Favaron/M/95,090/Senior Sales Manager/01Jul2001
121144/Renee/Capachietti/F/83,505/Sales Manager/01Nov1995
121145/Dennis/Lansberry/M/84,260/Sales Manager/01Apr1980
;

 

Fiery
Obsidian | Level 7

Hi Tom, 

 

Thanks!  I saw the error, since I didn't know that CARDS/DATALINES needs to be the last statement in the DATA step, I couldn't figure out what was wrong. Now I know! 

 

Thanks for your time.  🙂 

 

Fiery 

Reeza
Super User

Statements after the CARDS/DATALINE statement are assumed to be data or are otherwise ignored. 

So in this case the location of your FORMAT statement matters, it usually doesn't. 


@Fiery wrote:

Hello, 

 

my understanding about FORMAT in SAS is if you add the format statement in DATA step, it creates permanent format. If the format statement is added to PROC print step, it only creates the format on the output.  However, when I write the following programs, the format for the variable" HireDate" didn't change, it still appears as SAS data value.  But when I move the format statement to PROC PRINT step, it shows correctly.  Why is that?  Did I miss anything?  Thanks for your help.

 

data work.sales;
infile datalines dlm="/";
input ID First :$12. Last :$12. Gender $ Salary:comma. Title :$25. HireDate :date.;
datalines;
120102/Tom/Zhou/M/108,255/Sales Manager/01Jun1993
120103/Wilson/Dawes/M/87,975/Sales Manager/01Jan1978
120261/Harry/Highpoint/M/243,190/Chief Sales Officer/01Aug1991
121143/Louis/Favaron/M/95,090/Senior Sales Manager/01Jul2001
121144/Renee/Capachietti/F/83,505/Sales Manager/01Nov1995
121145/Dennis/Lansberry/M/84,260/Sales Manager/01Apr1980
;
format HireDate mmddyy10.;
run;

Title "Orion Star Management Team";
proc print data=work.sales;
run;
Title;

Capture.JPG


 

 

 

Fiery
Obsidian | Level 7

Hi Kurt, 

 

Thanks for sharing this link, it is indeed very useful for a fresh leaner like me. I am teaching myself by using internet. It is possible sometime miss out some key points. It is great thing to have the community, so I can get helps from experts like you guys. 

 

Thank you! 

 

Fiery 

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
  • 7 replies
  • 1034 views
  • 5 likes
  • 5 in conversation