BookmarkSubscribeRSS Feed
amajeau
Fluorite | Level 6

If I have a variable (var) such that if category= A then the value of var is 1, if category=B then value of var is 2, and if category =C then the value of var is 3 and I want to create indicator variables for these three categories of var, called var_1, var_2, and var_3 using macros, would it be correct to say

 

%macros Create_indictor (num=);

data= mydata;

if var= &num then %put var_#

run;

%mend Create_indicator;

 

%Create_indicator (num=1);

%Create_indicator (num=2);

%Create_indicator (num=3);

 

 

1 REPLY 1
Reeza
Super User

Let's not reinvent the wheel 🙂 

 

SAS provides functionality to handle categorical variables, depending on your procedure. 

Or you can use the methods here:

http://blogs.sas.com/content/iml/2016/02/22/create-dummy-variables-in-sas.html

 

At the bottom of this page there are three other links with ways to create dummy variables

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-dummy-variables-Categorical-Var...

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
  • 1 reply
  • 4295 views
  • 4 likes
  • 2 in conversation