DATA Step, Macro, Functions and more

Proc format error

Reply
Frequent Contributor
Frequent Contributor
Posts: 78

Proc format error

Hello, 

 

I tried to use the followng format and put function to revalue yr_qt variable, however the first row of the format could not show off  ("2011_Q1"='1.2011_Q1' ). After put function, the 2011_Q1 is still 2011_Q1 instead of  1.2011_Q1 .

 

I am wondering what is wrong.  Thank you very much.

 

proc format ;
value
$yr_qtf 30.
"2011_Q1"='1.2011_Q1'
"2011_Q2"='2.2011_Q2'
"2011_Q3"='3.2011_Q3'
"2011_Q4"='4.2011_Q4'
"2012_Q1"='5.2012_Q1'
"2012_Q2"='6.2012_Q2'
"2012_Q3"='7.2012_Q3'
"2012_Q4"='8.2012_Q4'
"2013_Q1"='9.2013_Q1'
"2013_Q2"='91.2013_Q2'
"2013_Q3"='92.2013_Q3'
"2013_Q4"='93.2013_Q4'
"2014_Q1"='94.2014_Q1'
"2014_Q2"='95.2014_Q2'
"2014_Q3"='96.2014_Q3'
"2014_Q4"='97.2014_Q4'
"2015_Q1"='98.2015_Q1'
"2015_Q2"='99.2015_Q2'
"2015_Q3"='991.2015_Q3'
"2015_Q4"='992.2015_Q4'
'All years'='0.ALL years'
;
run;

 

data table2;

set table2;

yr_qt_1 = put ( yr_qt, yr_qtf. ) ;

run;

 

 

 

Trusted Advisor
Posts: 1,131

Re: Proc format error

Please remove 30. from the proc format step and the format will work.

Please let me know if it does not work.
Thanks,
Jag
Frequent Contributor
Frequent Contributor
Posts: 78

Re: Proc format error

Thank you very much, it works !
Super User
Posts: 17,963

Re: Proc format error

Instead of this, you may want create a custom format to display the date in that format rather than add the 1. etc I'm assuming it's to order the data, but it looks uglier in my opinion in this format. In fact, it should sort naturally, so I'm not sure why you're doing this at all...

 

Look into proc picture and how to create a custom date format. 

 

You can also look into a multilabel format to create multiple levels when formatting. 

 

Formats are extremely powerful, they're worth learning well. 

 

To diagnose your problem with your format for example you can use the following to see how proc format stored the format and noticed that the first one was missing so you could check your code.

 

proc format cntlout=check_format;
run;

proc print data=check_format;
run;

 

 

Ask a Question
Discussion stats
  • 3 replies
  • 246 views
  • 1 like
  • 3 in conversation