BookmarkSubscribeRSS Feed
tarun_2202
Calcite | Level 5

data _null_;

set sashelp.class end = last;

call symput ('sname' || trim(left(_n_)) , name);

if last then call symput ('var_count' , _n_);

run;

 

%macro newvar;

data output;

set sashelp.class;

%do = 1 %to &var_count;

&&sname&i = (name = "&&sname&i");

%end;

 

%newvar;

%mend;

4 REPLIES 4
Reeza
Super User
Did you run it? Also....you have some interesting variable names that make me not want to answer your question.
tarun_2202
Calcite | Level 5
Hi,
In Output of this code, dummy variable created with same name as value of name variable having value of 0 and 1 ...
Kurt_Bremser
Super User

You can achieve something similar without macro coding:

data class;
set sashelp.class;
value = 1;
run;

proc transpose data=class out=want (drop=_name_);
by name age sex weight height;
var value;
id name;
run;
Ksharp
Super User

It is the same as 

 

data have;
 set sashelp.class;
 dummy=1;
run;
proc logistic data=have outdesign=want(drop=intercept dummy) outdesignonly;
class name/param=glm;
model dummy=name;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 339 views
  • 0 likes
  • 4 in conversation