For instance I have my variables - Labels in the below fomat:
CELL_CALL_CNT_M1 - count of cell calls-April
CELL_CALL_CNT_M2 - count of cell calls-May
CELL_CALL_CNT_M3 - count of cell calls-June
CELL_CALL_CNT_M4 - count of cell calls-July
CELL_CALL_CNT_M5 - count of cell calls-August
CELL_CALL_CNT_M6 - count of cell calls-September
Say, I'd like to filter out data for the months of April, May & June. So I was thinking if we can apply filters on labels.
Any suggestions !??
No.
If you explain your situation and problem with some detail perhaps we can make alternative suggestions.
Hi @pradeepvaranasi,
If you mean something like "restrict a dataset or apply a procedure to variables whose labels meet certain criteria," then yes: We can create the corresponding variable list by means of PROC SQL and DICTIONARY.COLUMNS and then use it in a suitable statement or dataset option.
Example: Restrict PROC PRINT output of SASHELP.DEMOGRAPHICS to country name and variables whose labels mention the year 2005.
proc sql noprint;
select name into :vlist separated by ' '
from dictionary.columns
where libname='SASHELP' & memname='DEMOGRAPHICS'
& findw(label, '2005');
quit;
proc print data=sashelp.demographics(obs=10) label;
var isoname &vlist;
run;
Does this imply that at some time you have lables with values for April associated with a different variable name? If not then just keep the correct variables. If the differing names is the case then the data should be normalized (probably transposed ) to include a separate variable to indicate the month and then the exercise becomes selecting the values of month (or date even).
Hi @pradeepvaranasi,
Thanks for adding more details to your initial post. It seems that the technique I suggested is applicable. Here's how:
/* Create test data */
data have;
label CELL_CALL_CNT_M1 = 'count of cell calls-April'
CELL_CALL_CNT_M2 = 'count of cell calls-May'
CELL_CALL_CNT_M3 = 'count of cell calls-June'
CELL_CALL_CNT_M4 = 'count of cell calls-July'
CELL_CALL_CNT_M5 = 'count of cell calls-August'
CELL_CALL_CNT_M6 = 'count of cell calls-September'
;
length C: 8;
run; /* dataset with 6 variables */
/* Select variables */
proc sql noprint;
select name into :vlist separated by ' '
from dictionary.columns
where libname='WORK' & memname='HAVE'
& scan(label,2,'-') in ('April','May','June');
quit;
data want;
set have(keep=&vlist);
run; /* dataset with 3 variables */
As you see, you can choose the appropriate character function, be it FINDW (as in my first example), SCAN (as above), INDEX, ..., and logical operators to specify your filter criterion on the labels.
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.
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.