DATA Step, Macro, Functions and more

How to create the following data step or macro variable.

Accepted Solution Solved
Reply
Contributor
Posts: 21
Accepted Solution

How to create the following data step or macro variable.

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

Accepted Solutions
Solution
‎06-28-2016 04:18 PM
Super User
Posts: 19,772

Re: How to create the following data step or macro variable.

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


All Replies
Contributor
Posts: 21

Re: How to create the following data step or macro variable.

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? 

Solution
‎06-28-2016 04:18 PM
Super User
Posts: 19,772

Re: How to create the following data step or macro variable.

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;
Contributor
Posts: 21

Re: How to create the following data step or macro variable.

Awesome ! Thanks for your help !
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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