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_);



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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1314 views
  • 1 like
  • 3 in conversation