I am trying to create a dummy variable where if weekday=1, then Monday=1...
so far I have this:
data want set have; if weekday=1 then mon=1; else mon=0; run;
but this does not actually create the variable, what am I missing?
if weekday in (2, 3, 4) then TWT=1;
We would need to see a (portion of) your data. We can't answer your question without it. (Or better yet, YOU look at the data and see if you can figure out why this simple code isn't working, before asking us. Don't actually ask us without YOU looking at the data first to see if you can figure it out)
Do you have a variable called weekday in your data? Or do you simply have a date variable?
If the latter is the case, you should use the WEEKDAY Function instead.
Anyway, always a good idea to specify what your data looks like
if weekday in (2, 3, 4) then TWT=1;
You have to stop telling us "doesn't work". You have to explain what happened and what you expected to happen. You have to show us the SASLOG.
25 if weekday=0 then sun=1; 26 else sun=0; 27 if Temperature =< 75 then low=1; 28 else low=0; 29 if Temperature between 75 and 85 then mid=1; _______ 388 202 ERROR 388-185: Expecting an arithmetic operator.
I'm sorry, I just thought it would be enough
won't happen again
if (75 <= var <= 85) then .......
@Astounding wrote:
if weekday in (2, 3, 4) then TWT=1;
Twt= weekday in (2, 3, 4);
Avoids need for Else twt=0.
Did you read the log?
You are missing a semicolon at the end of the DATA statement. Depending on the setting for system options, using SET as a data set name may or may not generate an error message. You will have to check to see whether your original data set is intact or not.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.