BookmarkSubscribeRSS Feed
apple
Calcite | Level 5

data AGE;

set B;

where AGE =>65 OR AGE<12;

run;

I want to have a dataset with records that have AGE=>65 or AGE<12, but the above code doesn't work.

I get this in the log:

                  _
                  22
                  76

ERROR: Syntax error while parsing WHERE clause.

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,

          a missing value, INPUT, PUT. 

ERROR 76-322: Syntax error, statement will be ignored.

3 REPLIES 3
data_null__
Jade | Level 19

You need >= or (and I never say always but) I always use mnemonics GE.

18         data _null_;
19            set sashelp.class;
20            where AGE >=65 OR AGE<12;
21            put _all_;
22            run;

Name=Joyce Sex=F Age=
11 Height=51.3 Weight=50.5 _ERROR_=0 _N_=1
Name=Thomas Sex=M Age=
11 Height=57.5 Weight=85 _ERROR_=0 _N_=2
NOTE: There were
2 observations read from the data set SASHELP.CLASS.
      WHERE  not (AGE>=
12 and AGE<65);
rnmishra
Calcite | Level 5

To  avoid confusion with those symbols, I always use  GE for >= (Greater than or Equal to)   and LT for < (Less Than).

Thanks!

apple
Calcite | Level 5

Thanks for all the helpful comments.

But now I notice that I have some records with Age=.

So now I want age that are also 0=<AGE<12.

Thanks

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 473 views
  • 0 likes
  • 3 in conversation