BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
matt23
Quartz | Level 8

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

if weekday in (2, 3, 4) then TWT=1;

View solution in original post

12 REPLIES 12
PaigeMiller
Diamond | Level 26

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)

--
Paige Miller
PeterClemmensen
Tourmaline | Level 20

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

matt23
Quartz | Level 8
I do have a variable called weekday that goes from 0 to 6
matt23
Quartz | Level 8
nvm I got it working
matt23
Quartz | Level 8
Sorry, one more question:

if this works, if weekday=1 then mon=1;
else mon=0;

then how would I do if weekday=2,3,4 then TWT=1 ??
Astounding
PROC Star

if weekday in (2, 3, 4) then TWT=1;

matt23
Quartz | Level 8
how would I do that if I want a variables that is between two values like between 75 and 85? (75:85) only gives me full values but I have decimals in them so this doesn't work and the statement 'between' does not seem to work
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
matt23
Quartz | Level 8
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

Astounding
PROC Star

if (75 <= var <= 85) then .......

ballardw
Super User

@Astounding wrote:

if weekday in (2, 3, 4) then TWT=1;


Twt= weekday in (2, 3, 4);

 

Avoids need for Else twt=0.

Astounding
PROC Star

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 12 replies
  • 3066 views
  • 2 likes
  • 5 in conversation