Help using Base SAS procedures

performing function on 11k variables

Reply
Contributor
Posts: 22

performing function on 11k variables

the goal of the below program is to count the numeric values pass the decimal point.
if the selected variable has numbers after the decimal the name is recorded. overall i want a file with the applicable variables names.

the problem is that i am trying to resolve is to perform this operator for 11k variables. i have tried to load the vars in a macro but they exceed the max length. i have also tried some proc sql steps but admit that i dont use sql. any suggestions?

%let var=weight;
data mac;
set desk.opa(keep=&var) end=eof;

length name $ 25;
hasFlag = (length(trim(left(scan(&var , 2 , '.' ))))) > 2 ;
if hasFlag >0 then count+ 1;
if count gt 0 then NAME="&var";
if eof then output;

run;
this works as desired but for only this var.


tried


proc sql noprint ;

create table vars as
select name
from dictionary.columns
where memname = 'OPA'
order by name ;

select distinct name
into Smiley Surprisedrigvars separated by ' '
from vars
order by name ;

quit ;

%let var=&origvars;
data mac;
set desk.opa(keep=&var) end=eof;

length name $ 25;
hasFlag = (length(trim(left(scan(&var , 2 , '.' ))))) > 2 ;
if hasFlag >0 then count+ 1;
if count gt 0 then NAME="&var";
if eof then output;

run;
this is where i get "exceeds max length error" and the "expecting a arithmetic operator", separating the string of variables. this was not resolved but changing the into Smiley Surprisedrigvars separated by ' ' to into Smiley Surprisedrigvars separated by ','
Super Contributor
Super Contributor
Posts: 3,174

Re: performing function on 11k variables

You can drive this process using an ARRAY in a single DATA step pass of each file. The ARRAY can be declared so that only _NUMERIC_ variables are included, presuming you are not attempting to parse CHARACTER type variables that contain numbers, otherwise the array can be declared with _ALL_ to process all CHARACTER and NUMERIC type variables.

Also, when you detect a variable that has the required data-string content (beyond 1 decimal place), you could identify the array subscript as a "keeper", maybe using CALL SYMPUT, once you have detected at least one observation that has the variable content.

These are but a few points relative to how you might want to consider optimizing the processing to reach your objective.


Scott Barry
SBBWorks, Inc.
Contributor
Posts: 22

Re: performing function on 11k variables

Thanks for the reply Scott,

I actually did try one of your suggestions- _NUMERIC_ as in:


data test;
set desk.Opa;
array allvar ( * ) &origvars _NUMERIC_;
do i = 1 to dim ( allvar ) ;
hasFlag = (length(trim(left(scan(allvar(i) , 2 , '.' ))))) > 2 ;
if hasFlag >0 then count+ 1;
if count > 0 then NAME="&origvars";
end ;
run ;

unfortnately my data exceeds the max length. i will research the CALL SYMPUT though.

Thanks again
Ask a Question
Discussion stats
  • 2 replies
  • 92 views
  • 0 likes
  • 2 in conversation