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;
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*/
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*/
Thanks, it worked perfectly.
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.));
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.
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.