BookmarkSubscribeRSS Feed
pnp123
Calcite | Level 5

Data test;

     put  

      abc $3.

      qrs $3.

      xyz $5.;

 

    do 1 to 20;

      abc="djsdfsdk";

      qrs="sdui";

      xyz="YHTyuh";

   end;

output;

run;

 

i need to create  macro variable for abc, qrs, xyz

Can anybody please help

 

4 REPLIES 4
error_prone
Barite | Level 11
What do you want to do with the macro variables? What should they contain?

The position of the output statement seems to be wrong.
PeterClemmensen
Tourmaline | Level 20

For what purpose is this code? It makes very little sense.

 

You can use the CALL SYMPUTX Routine to create macro variables in a data step

 

 

Kurt_Bremser
Super User

Before you even think about dealing with the macro preprocessor, you need to get a grasp of basic SAS data step principles, which you very obviously have not yet managed to do:

Data test;
     put  
      abc $3.
      qrs $3.
      xyz $5.; /* This put statement makes no sense, as the variables have no values yet */
 
    do 1 to 20;
      abc="djsdfsdk";
      qrs="sdui";
      xyz="YHTyuh";
   end; /* this do loop also makes no sense, as it just sets the same values 20 times in succession. Just a waste of CPU cycles */
output; /* this statement is not necessary, as the data step will perform an implicit output of it's own at the end of an iteration */
run;
Reeza
Super User

You create macro variables in a data step using CALL SYMPUTX(). 

 

Your question is too vague to answer, so given how you've stated it, this would be 'correct':

 

%let macro1=abc;
%let macro2=qrs;
%let macro3=xyz;

You should also look into how PROC SQL can create macro variables, it's quite efficient at doing so, check the documentation for the relevant section with full examples:

proc sql noprint;
select name into :name1-
from sashelp.class;
quit;

%put &name1.;
%put &name19.;

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 867 views
  • 2 likes
  • 5 in conversation