BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aboiron
Calcite | Level 5

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

data seuils_60;

  seuill=&seuil_60_14 ;

run;

 

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

4 REPLIES 4
mkeintz
PROC Star

data seuils_60;

  seuill=&seuil_60_14 ;

run;

 

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Damien_Mather
Lapis Lazuli | Level 10

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.

Damien_Mather
Lapis Lazuli | Level 10
oops I meant to only type populate!
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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