BookmarkSubscribeRSS Feed
mj5
Obsidian | Level 7 mj5
Obsidian | Level 7

I am using the below step to check if the variables are not missing than concatenate. can i use these sec1 and sec2 in macro call because i dont know how many sec.. will be  coming later.

any idea?

if SEC1 ne '' and SEC2 ne '' then do;
        sec_r=catx(';', of SEC:);¨
end;
3 REPLIES 3
Criptic
Lapis Lazuli | Level 10
I did something like this where I passed all these values as one String in a macro variable separated by ','. Then I count the number of words (countw()) and do a do-loop in which I concat the variables into a new variable.
Criptic
Lapis Lazuli | Level 10
data _null_;
  counter = countw(sec_all, ',');
  do i=1 to counter by 2;
   sec_cat = trim(catt("&sec_at", scan(sec_all, i, ','));
  end;
run;

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

I am sorry, I don't follow you.  The catx(';',of sec:) will concatenate all non missing variables with prefix sec together.  I don't see where the need to use macro or check missing comes from?  Please provide good examples - post test data in the form of a datastep and what you expect as output.  Remember macro SAS is not a replacement for Base SAS, and doesn't do anything magical. 

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
  • 3 replies
  • 621 views
  • 0 likes
  • 3 in conversation