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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1203 views
  • 2 likes
  • 4 in conversation