BookmarkSubscribeRSS Feed
pradeepvaranasi
Calcite | Level 5

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 !?? 

5 REPLIES 5
Reeza
Super User

No.

 

If you explain your situation and problem with some detail perhaps we can make alternative suggestions. 

FreelanceReinh
Jade | Level 19

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;

 

 

Reeza
Super User
IMO that doesn't use the labels in filter, except in a roundabout way. Theoretically can also use vlabel but depends on what OP wants.
ballardw
Super User

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).

FreelanceReinh
Jade | Level 19

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 5 replies
  • 1613 views
  • 0 likes
  • 4 in conversation