BookmarkSubscribeRSS Feed
Hart
Calcite | Level 5
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 :origvars 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 :origvars separated by ' ' to into :origvars separated by ','
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Hart
Calcite | Level 5
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
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1223 views
  • 0 likes
  • 2 in conversation