BookmarkSubscribeRSS Feed
JP1234
Calcite | Level 5

I have a date

%let mydate = 20180112; /*yyyymmdd */

I want to create macro vaiable suffix = 201709_201811; /*(yyyymm-yyyymm)*/

 

How can i do that?

Thanks,

Jeff

4 REPLIES 4
PaigeMiller
Diamond | Level 26

I'm probably not understanding the problem, but ... based on what you said, you create the suffix macro variable as

 

%let suffix = 201709_201811;
--
Paige Miller
JP1234
Calcite | Level 5

I want to derive suffix from my_date for later use.

 

I tried this code but it did not work

%let my_date = 20180112; /* YYYYMMDD */

data suff;

format ref_date date9.;

ref_date = mdy(substr(put(&my_date,$8.),5,2), substr(put(&scoring_date,$8.),7,2), substr(put(&scoring_date,$8.),1,4));

suffix=catx('_','put(intnx('month',ref_date,-16),yymm.));',put(intnx('month',ref_date,-1),yymm.));

 

run;

 

proc sql;

select suffix into :suffix 

from suff;

quit.



 

it doest work.

Thanks,

Jeff

quit;

Cynthia_sas
SAS Super FREQ

Hi:
Saying it just doesn't work is rather vague. Are you getting ERROR messages or WARNING messages in the SAS log? If so, have you tried to determine why you're getting those messages?

What is the purpose of the SQL step? If you need a macro variable why not create it with CALL SYMPUT in the DATA step program where you are creating SUFFIX?? You don't need a separate SQL step.

What is the disposition of &SUFFIX or, how do you plan to use it? Why is &MY_DATE a macro variable? What is the value for &SCORING_DATE? No one can run your code because you only provide a value for &MY_DATE.

Since no one can run your code without values for &SCORING_DATE and since you have an error in the SQL code (period after quit), It is hard to figure out what you need or why you've used this approach.

Can you clarify?
Thanks,
Cynthia

ballardw
Super User

Why not use

 

Ref_date= input("&my_date.",yymmdd8);

 

instead of futzing around with string functions AND not ever turning the strings into the numeric values that MDY requires. Which is what is generating multiple errors in your existing code.

 

Or changing the value of your my_date variable and using that directly

 

%let mydate=12JAN2018;

suffix=catx('_','put(intnx('month', "&my_date."d ,-16),yymm.));',put(intnx('month', "&my_date."d ,-1),yymm.));

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 805 views
  • 0 likes
  • 4 in conversation