BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
texasmfp
Lapis Lazuli | Level 10

Is it possible to insert a macro variable into  CARDS lines.  For example, suppose I have a date variable (MO_YEAR) with a value of "08-2023' that I want to insert into the pdf file names to make the filename dynamic each month

data W47XXFM;
input file_name $ : 20.;
cards;
test.pdf
test1.pdf
test2.pdf
;
run;

such that when run, the file names in data W47XXFM resolve to:

08-2023 test.pdf
08-2023 test1.pdf
08-2023 test2.pdf

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

It is not possible to use macro triggers in CARDS/DATALINES.

But you can write the DATA step containing the CARDS to a temporary file and %INCLUDE that, or incorporate the macro variable in the code:

%let macvar = 08-2023;

data W47XXFM;
length file_name $20;
input file_name $20.;
file_name = "&macvar." !! file_name;
cards;
test.pdf
test1.pdf
test2.pdf
;

View solution in original post

6 REPLIES 6
andreas_lds
PROC Star

What happens, when you try it? Have you read the documentation of CARDS? Hint: https://documentation.sas.com/doc/de/pgmsascdc/9.4_3.5/mcrolref/p10yr6jbpc8t6dn1xurxomzg37fl.htm

 

WarrenKuhfeld
Rhodochrosite | Level 12

No.

Kurt_Bremser
Super User

It is not possible to use macro triggers in CARDS/DATALINES.

But you can write the DATA step containing the CARDS to a temporary file and %INCLUDE that, or incorporate the macro variable in the code:

%let macvar = 08-2023;

data W47XXFM;
length file_name $20;
input file_name $20.;
file_name = "&macvar." !! file_name;
cards;
test.pdf
test1.pdf
test2.pdf
;
texasmfp
Lapis Lazuli | Level 10

Thanks Kurt

Patrick
Opal | Level 21

Is below what you're asking for?

%let mo_year=08-2023;
data demo;
  input file_name $40.;
  file_name=resolve(file_name);
  cards;
&mo_year test.pdf
&mo_year test1.pdf
&mo_year test2.pdf
;

proc print data=demo;
run;

Patrick_0-1691394590562.png

 

texasmfp
Lapis Lazuli | Level 10

Yes, thanks.  Looks like there are two workarounds,  However, Kurt's code works better with variable filename lengths. 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 367 views
  • 3 likes
  • 5 in conversation