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

Users define a couple of macro variables (input):

%let category = A B;
%let class = apple banana;
%let column = index character;

The generated table/dataset (output) would look like:

category class index character
   A     apple   .       .
   A     banana  .       .
   B     apple   .       .
   B     banana  .       .

As you can see, for column 1 and column 2, they basically go through values of the macro variables, with macro variables' names as the column names. For column 3 and column 4, blanks, with macro variable's value as the column names (column 'index' has numeric values; column 'character' has char.)

 

How to achieve it?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Untested, so it's possible it needs a little debugging:

 

%macro generate (category=, class=, column=);

 

%local i j;

data want;

length category class $ 8 &column 8;

%do i=1 %to %sysfunc(countw(&category));

%do j=1 %to %sysfunc(countw(&class));

category = "%scan(&category, &i)";

class = "%scan(&class, &j)";

output;

%end;

%end;

run;

 

%mend generate;

 

%generate (category=A B, class=apple banana, column=index character)

View solution in original post

1 REPLY 1
Astounding
PROC Star

Untested, so it's possible it needs a little debugging:

 

%macro generate (category=, class=, column=);

 

%local i j;

data want;

length category class $ 8 &column 8;

%do i=1 %to %sysfunc(countw(&category));

%do j=1 %to %sysfunc(countw(&class));

category = "%scan(&category, &i)";

class = "%scan(&class, &j)";

output;

%end;

%end;

run;

 

%mend generate;

 

%generate (category=A B, class=apple banana, column=index character)

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1 reply
  • 8691 views
  • 1 like
  • 2 in conversation