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

When I set month to fiscal month it saves correctly to the datastep but when I use fiscal_month in a concatenation it uses the value not the format.  The format alone works correctly.

 

How can I save the formatted value to the data table.  In this case I am trying to save to Fiscal Period Year.

 

My dataset ends up looking like 20157 rather than 201501.

 

PROC FORMAT;

     value Fiscal_Period_Format

     1='07'

     2='08'

     3='09'

     4='10'

     5='11'

     6='12'

     7='01'

     8='02'

     9='03'

     10='04'

     11='05'

     12='06';

RUN;

 

data ProposalsCombined; set P1;

    

     format Fiscal_Period Fiscal_Period_Format.;

     if(month(Submit_date) >= 7) then

           Fiscal_Year = year(datepart(Submit_Date));

     else

           Fiscal_Year = year(datepart(Submit_Date)) + 1;

     Fiscal_Period = month(datepart(Submit_Date)); /*this works*/

     Fiscal_period_Year = trim(left(Fiscal_Year)) || trim(left(Fiscal_Period)); /*this does not format*/

run;

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

As its a string you need to "put" the value into its format:

 Fiscal_period_Year = trim(left(Fiscal_Year)) || trim(left(put(Fiscal_Period,fiscal_period_format.))); /*this does not format*/

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

As its a string you need to "put" the value into its format:

 Fiscal_period_Year = trim(left(Fiscal_Year)) || trim(left(put(Fiscal_Period,fiscal_period_format.))); /*this does not format*/

DavidPhillips2
Rhodochrosite | Level 12

Thanks, it worked perfectly.

PaigeMiller
Diamond | Level 26

Concatenate (and all other functions) uses the actual value, not the formatted value.

 

You want

 

Fiscal_period_Year = trim(left(Fiscal_Year)) || trim(left(put(Fiscal_Period,fiscal_period_format.)));

 

or better yet

 

fiscal_period_year=cats(fiscal_year,put(Fiscal_Period,fiscal_period_format.));
--
Paige Miller

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
  • 5560 views
  • 3 likes
  • 3 in conversation