BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ram_SAS
Obsidian | Level 7
From the following observations I need to create two variable var101 and var102 (either data step or macro variable).
 
ID      numvalue
101     23
101     27
101     29
101     22
102     23
 102    32
 
var101 = 23 27 29
var102 = 22 23 32
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Multiple queries? But why? 

 

You could also use a data step that concatenates variable and creates macro variable at the end of each group id. 

 

Untested but the gist of the idea is there. 

 

Data _null_;
Length var_string $200.;
Set have;

By id;
Retain var_string;
If first.id then call missing(var_string);

Var_string = catt(var_string, value);

If last.id then call symputx('var'|put(id, z3.), var_string);

Run;

View solution in original post

3 REPLIES 3
Ram_SAS
Obsidian | Level 7

The SQL into clause could load everything into one macro variable, but I want to group them into different variables based on the ID. Any suggestions? 

Reeza
Super User

Multiple queries? But why? 

 

You could also use a data step that concatenates variable and creates macro variable at the end of each group id. 

 

Untested but the gist of the idea is there. 

 

Data _null_;
Length var_string $200.;
Set have;

By id;
Retain var_string;
If first.id then call missing(var_string);

Var_string = catt(var_string, value);

If last.id then call symputx('var'|put(id, z3.), var_string);

Run;
Ram_SAS
Obsidian | Level 7
Awesome ! Thanks for your help !

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1544 views
  • 0 likes
  • 2 in conversation