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

Hello,

 

I am trying to code all variables in my dataset so that any observations less than 0 are coded as missing.

 

I tried something like this, but I guess the "_ALL_" trick only works in certain situations and doesn't work here?

if _ALL_ < 0 then _ALL_=.;

 

Does anyone know of an easier way to get SAS to perform this data step all at once, without me having to list each variable on their own on a separate line?

 

Thank you!!!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

I assume you have all numeric variables, as <0 doesn't apply to character variables. So ... the data step method you need is called an ARRAY.

 

data want;
    set have;
    array x _numeric_;
    do i=1 to dim(x);
        if x(i)<0 then call missing(x(i));
    end;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

I assume you have all numeric variables, as <0 doesn't apply to character variables. So ... the data step method you need is called an ARRAY.

 

data want;
    set have;
    array x _numeric_;
    do i=1 to dim(x);
        if x(i)<0 then call missing(x(i));
    end;
run;
--
Paige Miller
Reeza
Super User
Your logic can also be reduced to the maximum of a series being less than 0. Note that rows of missing will evaluate as true and all will be set to missing, which is the same so a non-issue.


if max(of _numeric_) < 0 then call missing(of _numeric_);



sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 491 views
  • 1 like
  • 3 in conversation