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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

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
  • 12 replies
  • 1351 views
  • 2 likes
  • 5 in conversation