BookmarkSubscribeRSS Feed
subrat1
Fluorite | Level 6

i want to creat a macro variable to store (2,4,15,16) in it, How to do this?

6 REPLIES 6
subrat1
Fluorite | Level 6

create a macro variable to store fixed constant integer so that i can pass that in my program.

like for example     %Let  a= (4, 5, 6)      but this is not working

Kurt_Bremser
Super User

"this is not working" is not helpful.

You need to be much more specific, ie by posting the relevant piece of code and the log, and the data as it came out and as you wanted it to be.

Astounding
PROC Star

Why do you say it's not working?  It's easy to check.  Assuming you added a semicolon:

 

%let a = (4, 5, 6);

%put **&a**;

 

What's actually happening is that the statement works, but you don't know what to do with the result.  It is highly likely that you should heed the suggestion about keeping data in data sets instead of macro variables.  If you show what you are trying to accomplish, you are pretty sure to get some helpful suggestions.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Why?  Why not put that list of "data" items in a "data"set that is what "datasets" are for storing data.  Macro language is not a replacement for Base SAS - it is a text generation tool.

Cynthia_sas
Diamond | Level 26

Hi:

  Consider this program (with different numbers so I could use it with SASHELP.CLASS):

title; footnote;

%let a=(14,15,16);
%put -----> macro variable a is: &a;

options mprint symbolgen;
proc print data=sashelp.class;
  title "Looking for Ages &a";
  where age in &a;
run;
  
   
data new;
  x = sum&a;
run;
  
proc print data=new;
title "adding up values &a in parentheses with sum function";
run;
title;

Illustrates 2 completely different uses of &a in 2 different steps. So what the OP wants and what the data looks like and the reason for having the  numbers in a macro variable need to be explained so that everybody understands WHAT the OP is trying to accomplish.

 

The above program generates this in the log and output:

forum_macro.png

 

But without a context for the question, it's hard to know which generated code is the desired aim.

 

cynthia

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2991 views
  • 1 like
  • 5 in conversation