I need help changing my year variable into a dummy variable, so i can run this macro.
The variable year variable is currently a numeric variable (2010-2017).
Thank you
Most likely, you will end up using YEAR as is. Analytical procedures will normally let you use this statement:
class year;
That will create dummy variables as needed.
If you really have to have a dummy variable, one dummy variable is not enough. You have 8 values for YEAR. You will need 7 dummy variables (rarely 8, depending on your intentions). Does that fit your plan?
Assuming you successfully did something along these lines:
2010=0
2011=1
2012=2
...
2017=7
You would be no better off than if you had done nothing. The original variable YEAR with values 2010-2017 could have been used any place these new values could be used.
If you want advice about using a set of values within a macro, you might need to post the macro.
Here's one way, data step methods:
*declare an array;
array _years(2012:2017) year2012-year2017;
*set all values to 0 initially;
do i=lbound(_years) to hbound(_years);
_years(i) = 0;
end;
*assign year to 1;
_years(year) = 1;
and here's another, more automated:
PS please post your code as text not as an image. An image means if we wanted to modify or include your code we have to type it out.
@Tobiasp94 wrote:
I need help changing my year variable into a dummy variable, so i can run this macro.
The variable year variable is currently a numeric variable (2010-2017).Thank you
You are doing some type of modeling in IML.
Unless it is a modeling technique not available elsewhere in SAS, don't do it in IML. Save yourself a lot of trouble, use the modeling PROCs that SAS has built and debugged, most of which use the CLASS statement so you don't have to create your own dummy variables.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.