DATA Step, Macro, Functions and more

Keeping a format while using Concatenate

Accepted Solution Solved
Reply
Super Contributor
Posts: 477
Accepted Solution

Keeping a format while using Concatenate

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;


Accepted Solutions
Solution
‎12-07-2015 10:33 AM
Super User
Super User
Posts: 7,392

Re: Keeping a format while using Concatenate

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


All Replies
Solution
‎12-07-2015 10:33 AM
Super User
Super User
Posts: 7,392

Re: Keeping a format while using Concatenate

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*/

Super Contributor
Posts: 477

Re: Keeping a format while using Concatenate

Thanks, it worked perfectly.

Trusted Advisor
Posts: 1,606

Re: Keeping a format while using Concatenate

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.));
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 186 views
  • 0 likes
  • 3 in conversation