DATA Step, Macro, Functions and more

create a macro variable which will store list of integer

Reply
Contributor
Posts: 48

create a macro variable which will store list of integer

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

Super User
Posts: 7,778

Re: create a macro variable which will store list of integer

Two questions:

- where is the list coming from (fixed constant, dataset, ....)?

- how should it be used (determines the format of the list)?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 48

Re: create a macro variable which will store list of integer

Posted in reply to KurtBremser

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

Super User
Posts: 7,778

Re: create a macro variable which will store list of integer

"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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 5,503

Re: create a macro variable which will store list of integer

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.

Super User
Super User
Posts: 7,945

Re: create a macro variable which will store list of integer

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.

SAS Super FREQ
Posts: 8,864

Re: create a macro variable which will store list of integer

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

Ask a Question
Discussion stats
  • 6 replies
  • 308 views
  • 1 like
  • 5 in conversation