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

Could someone tell me why this code isn't working?

I have a data set called "Feb_2",

I'm creating a data set "Feb_3",

Feb_2 has a variable "Net Points" and if it's less than 0 I would like to have a new variable "Net_Point_Adj" set to 0, else if "Net Points" is 0 or greater, I'd like the new variable "Net_Point_Adj" to = the value of "Net Points".

SAMPLE 1

DATA Feb_3;

Set Feb_2;

IF Net_Points <0, THEN Net_Point_Adj = 0;

ELSE Net_Points_Adj = Net_Points;

RUN;

SAMPLE 2

DATA Feb_3;

Set Feb_2;

IF Net_Points <0, THEN Net_Point_Adj = 0;

ELSE IF Net_Points_Adj => 0, THEN Net_Point_Adj = Net_Points;

RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Why are you putting a comma after the value?

IF Net_Points <0, THEN Net_Point_Adj = 0;

This is invalid SAS code.


Secondly, may I suggest some code readability:

data Feb_3;

     set Feb_2;

     if Net_Points < 0 then Net_Point_Adj=0;

     else Net_Points_Adj=Net_Points;

run;

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Why are you putting a comma after the value?

IF Net_Points <0, THEN Net_Point_Adj = 0;

This is invalid SAS code.


Secondly, may I suggest some code readability:

data Feb_3;

     set Feb_2;

     if Net_Points < 0 then Net_Point_Adj=0;

     else Net_Points_Adj=Net_Points;

run;

GalacticAbacus
Obsidian | Level 7

I added the comma because I was being sloppy Smiley Sad Thank you.

And yes I'll be more vigilant in code organization.

Thanks again.

TS

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!

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
  • 2 replies
  • 446 views
  • 0 likes
  • 2 in conversation