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

Hello everyone,

 

I need to mask rows in a set of columns. For example, say I have five columns named Column 1 - 5. There are thousands of rows in each column and anything under a certain number I need to mask. I could do this in a datastep repeating the code for each Column name but the problem is that I have a large number of columns in my actual dataset. Is there a way to do an Array or use a Macro to mask the data?

 

Thanks!

 

DATA NEW_DATA; SET OLD_DATA;

 

IF COLUMN_1 < 10 THEN COLUMN_1 = .;

ETC...

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Your requirement for "NC" and "<10" not possible if the variables are numeric. BUT a custom format will work for most purposes:

 

Here is an example format

proc format library=work;
   Value MyValues
   . = 'NC'
   low - 10 = "<10"
   other = [Best10.]
   ;
run;


To see the effect

proc print data=have ;
   var <your variable names go here>;
   Format <list the variables that need the display format> MyValues. ;
run;

replace the text in <> above with your variable names and no <>.  Note the period at the end of MyValues in the Format statement. The period tells SAS that MyValues is the name of the format to apply to the variables listed before it.

 

View solution in original post

3 REPLIES 3
ballardw
Super User

I would ask what is the purpose of this "mask". If it is for printing to suppress values then it may be easier to use a format to display a blank;

 

If your condition for "masking" is the same for each variable and you actually want to remove the value from the data set then an array would be a good choice such as this:

 

data want;
   set have;
   array a <list names of variables>;
   do i = 1 to dim(a);
      if a[i] < 10 then a[i] = .;
   end;
run;

Which would set all the variables to missing if their value is less than 10.

 

If each variable has a different condtion then neither a macro or array will work.

PaulBear
Calcite | Level 5

Thank you for the quick reply.

 

All the variables have the same conditions but if the variable is blank then it needs to read NC and if is is < 10 then it needs to read < 10.

 

Thanks again!

ballardw
Super User

Your requirement for "NC" and "<10" not possible if the variables are numeric. BUT a custom format will work for most purposes:

 

Here is an example format

proc format library=work;
   Value MyValues
   . = 'NC'
   low - 10 = "<10"
   other = [Best10.]
   ;
run;


To see the effect

proc print data=have ;
   var <your variable names go here>;
   Format <list the variables that need the display format> MyValues. ;
run;

replace the text in <> above with your variable names and no <>.  Note the period at the end of MyValues in the Format statement. The period tells SAS that MyValues is the name of the format to apply to the variables listed before it.

 

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!

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