BookmarkSubscribeRSS Feed
Ivy
Quartz | Level 8 Ivy
Quartz | Level 8

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;

 

 

 

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16
Please remove 30. from the proc format step and the format will work.

Please let me know if it does not work.
Thanks,
Jag
Ivy
Quartz | Level 8 Ivy
Quartz | Level 8
Thank you very much, it works !
Reeza
Super User

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;

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 865 views
  • 1 like
  • 3 in conversation