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

I have variables name like this

 

Total1, Male 2 Female1,Total2, Male 2 Female2, Total3, Male 3 Female3, Total4, Male 4 Female4..... Total n, Male n, Female n.

Is there any shortcuts to such variable names to list for input statement?  Like X1 X2 X3 -->   X1- X3

1 ACCEPTED SOLUTION

Accepted Solutions
Chieko
Fluorite | Level 6

Thank you for your quick resposne to my question. I have more than 100 sets it would be useful

 

 

View solution in original post

5 REPLIES 5
Haikuo
Onyx | Level 15

You just did that! Have you tried?

 

data test;
input x1-x3;
cards;
 1 2 3
 ;

 Edit: After viewing @Reeza, I realize that I misread your question. Please ignore my response. I didn't delete it just for the sake of record.

Chieko
Fluorite | Level 6

Thank you anyway

Reeza
Super User
Unfortunately not 😞

You could create a macro to create the names, but if you only have 3 it's not useful.

data _null_;
length var $1000.;

do i=1 to 10;

var=catt(var, " Total"||put(i, 2. -l), " Male"||put(i, 2. -l), " Female"||put(i, 2. -l));
end;

call symputx('input_list', var);
run;

%put &input_list;

Chieko
Fluorite | Level 6

Thank you for your quick resposne to my question. I have more than 100 sets it would be useful

 

 

Astounding
PROC Star

You will need to know how many sets appear on a line.  And even then the programming is somewhat sophisticated:

 

data want;

infile rawdata dlm=',';

array total {5};

array male {5};

array female {5};

do J=1 to 5;

   input total{J} male{J} female{J} @  ;

end;

run;

 

The variables won't be stored in the same order internally, but you can certainly shorten the program.  Good luck.

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
  • 5 replies
  • 1172 views
  • 2 likes
  • 4 in conversation