BookmarkSubscribeRSS Feed
bnarang
Calcite | Level 5

Hi

Let's say we have a variable

%let Group = AA BB CC DD;

I would like to produce GROUP_1, GROUP_2 , GROUP_3, GROUP_4.

To start with :

I had a count with of all the words in Group with Countw and I got 4.

Now, next, I tried within a macro

Data _null_;

%do i = 1 %to &num_count;

   Group_&i. = %qscan(%bquote(&group), &i.,',');

  call symput("Group_&i." Group_&i.);

Run;

Am I doing right?

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16

hi,

please try the below code, as per your if we consider &num_count eq to 4 then

%let num_count=4;

%put &num_count;

Data test;

    do i = 1 to &num_count;

    group="group_"||strip(put(i,1.));

    output;

    end;

   

Run;

proc sql noprint;

    select group into :grp separated by ',' from test;

quit;

%put &grp;

Thanks,

Jag

Thanks,
Jag
bnarang
Calcite | Level 5

Thanks for reply. My system was down for some weeks so, could not reply.. Thanks, I have got the solution.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 847 views
  • 3 likes
  • 2 in conversation