Hi,
I am using SA Enterprise Guide and I have a user choice date in parameter which I called "dated", and is from this type: "06/01/2017".
I created three macro variable following this:
%let dated_year = %sysfunc(year("&dated."d));
%let dated_month = %sysfunc(month("&dated."d));
%let dated_ym = %sysfunc(cats(&dated_year, &dated_month));
First question:
when i put dated_year is correct: "2017".
But when I put dated_month, it's written "1" instead of "01"...it's not very important for dated_month but more problematic for dated_ym which is "20171" instead of "201701".
Do you know how I should do?
Second question:
I want to format these three macro variable in character, but I don't know how to do it. Do you have an idea?
Thanks
1, You can use formats to zero-fill your numbers, like this
%let dated_month = %sysfunc(putn(%sysfunc(month("&dated."d)), z2.));
2. Macro variables are always character strings, so you shouldn't have any problem. Can you describe what you're trying to do in a little more detail?
Tom
1, You can use formats to zero-fill your numbers, like this
%let dated_month = %sysfunc(putn(%sysfunc(month("&dated."d)), z2.));
2. Macro variables are always character strings, so you shouldn't have any problem. Can you describe what you're trying to do in a little more detail?
Tom
Also note, once you have implemented Tom's solution, the last statement can be simplified:
%let dated_ym = &dated_year.&dated_month.;
Thanks for both of you.
I can accept only one topic as a solution, but you both helped me... for the first question.
For the second:
I try to do something like that:
PROC SQL;
CREATE TABLE A
(DA_IN char(6));
INSERT INTO A values (&dated_ym.);
QUIT;
RUN;
And I got this.
Value 1 of VALUES clause 1 does not match the data type of the corresponding column in the object-item list (in the SELECT
clause).
Oups sorry I know, I just forgot the double-quotes :S
Sorry for this.
If it's not a semicolon I'm missing, it's a double quote!!
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.