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

I'm just getting started and it's very simple code in SAS University. What am I doing wrong??  I get the following message when I run my if-then statement: ERROR 180-322: Statement is not valid or it is used out of proper order. 

 

*libnames point to the folder that contains the datasets, not the individual datasets;
libname malawi '/folders/myfolders/'; 
*malawi is the name of the folders and mwfemale_pubuse is the name of the dataset;
proc contents data=malawi.mwfemale_pubuse;

*Age groups 13-17 and 18-24;
if 13 <= q2 <= 18 then agegroup= 1;
if 18 <= q2 <=24 then agegroup= 2;

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Try this:

 

 

data want;
  set malawi.mwfemale_pubuse;
if 13 <= q2 <= 18 then agegroup= 1;
if 18 <= q2 <=24 then agegroup= 2;
run;

 

View solution in original post

5 REPLIES 5
SASKiwi
PROC Star

Try this:

 

 

data want;
  set malawi.mwfemale_pubuse;
if 13 <= q2 <= 18 then agegroup= 1;
if 18 <= q2 <=24 then agegroup= 2;
run;

 

MINX
Obsidian | Level 7

@aliyahh IF statement can not be used in CONTENTS procedure. The CONTENTS procedure shows the contents of a SAS data set and prints the directory of the SAS library. If you want to do conditional derivation for agegroup, @SASKiwi gave you the best approach in DATA step.

Reeza
Super User

Always end your PROC/DATA STEP with a RUN (or quit). 

 

When creating new variables you need to explicitly tell SAS both what data set you're working with and what you're trying to create. This occurs within a DATA STEP. 

 

DATA <New>;

SET <source>;

 

code to do stuff goes here - like if/then;

 

run;

 

I believe theres a free ecourse available as well as numerous videos here

http://video.sas.com/#category/videos/how-to-tutorials

PGStats
Opal | Level 21

Note: avoid making ambiguous age group definitions (as it is in your example for q2=18)

 

*Age groups 13-17 and 18-24;
if 13 <= q2 <  18 then agegroup= 1;
if 18 <= q2 <= 24 then agegroup= 2;

PG
aliyahh
Calcite | Level 5

Thanks everyone!

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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