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...
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.
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.
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!
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.