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

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 890 views
  • 0 likes
  • 2 in conversation