DATA Step, Macro, Functions and more

How to create a database from scratch with macrovariables

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

How to create a database from scratch with macrovariables

I want to create a database such as :

data seuils_60;
    input seuil1;
    datalines;
    1080
    ;

Except that I would like 1080 not to be an actual number, but a value stocked in a macrovariable. But when I try

data seuils_60;
    input seuil1;
    datalines;
    &seuil_60_14
    ;

I get an error, although I can %put my macrovariable (it exists).

What would be the best way around ?


Accepted Solutions
Solution
‎12-08-2016 11:08 AM
Valued Guide
Posts: 797

Re: How to create a database from scratch with macrovariables

data seuils_60;

  seuill=&seuil_60_14 ;

run;

 

 

 

View solution in original post


All Replies
Solution
‎12-08-2016 11:08 AM
Valued Guide
Posts: 797

Re: How to create a database from scratch with macrovariables

data seuils_60;

  seuill=&seuil_60_14 ;

run;

 

 

 

Frequent Contributor
Posts: 130

Re: How to create a database from scratch with macrovariables

SAS has a prohibition against macrovariables in datalines/cards statements.

 

Use the

 

varname1=&macvarnam1.;

 

varname2=&macvarnam2.;

 ...

 

varnameN=&macvarnamN.;

 

output;

 

method to get around that.

 

If need to poopulate more than one data row, and more than one variable per data row, you can assign and reference macro arrays like:

 

%do i = 1 %to &n.;

 %do j = 1 %to &m.

   varnam&j.=&&mvar&i._&j..;

 %end;

%end;

 

where n and m are the rows and columns of the data you want to load respectively and your macro variables are named from mvar1_1 to mvar&n._&m.

Frequent Contributor
Posts: 130

Re: How to create a database from scratch with macrovariables

oops I meant to only type populate!
Super User
Super User
Posts: 7,401

Re: How to create a database from scratch with macrovariables

Sorry?  Where is the database in the question?  From what I can see is you want to assign a bit of text - macro is only text - to a variable.  So the question is why, as:

data want;
  seuil1=1060;
run;

Seems to be the code you want.  Without further information as to the why its hard to say, I mean what is 

&seuil_60_14

Why is it created, why does it contain data?

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 256 views
  • 1 like
  • 4 in conversation