sas - How to scan a numeric variable -


i have table this:

 lista_id  1 4 7 10 ...  

in total there 100 numbers.

i want call each 1 of these numbers macro created. trying use 'scan' read it's character variables. error when runned following code

there's code:

   proc sql;      select id into: lista_id separated '*'      work.amostra;     run;       proc sql;     select count(*) into: nr separated '*'     work.amostra;     run;      %macro ciclo_teste();      %let lim_msisdn = %eval(nr);     %let = %eval(1);      %do %while (&i<= &lim_msisdn);     %let ref = %scan(lista_id,&i,,'*');       data work.up&ref;     set work.base&ref;     format perc_acum 9.3;     if first.id_cliente perc_acum=0;     perc_acum+perc;     run;         %let = %eval(&i+1);     %end;     %mend;      %ciclo_teste; 

the error that:

variable perc unitialized and
variable first.id_cliente unitialized.

what want run macro each 1 of id's in list showed before, , referenced in work.base&ref , work.up&ref. how can it? i'm doing wrong?

thanks!

first should note sas macro variable resolve intrinsically "text-based" copy-paste action. is, user-defined macro variables texts. therefore, %eval unnecessary in case.

other miscellaneous corrections include:

  • check %scan() function correct usage. first argument should text string without quotes.

  • run redundant in proc sql since each sql statement run sent. use quit; exit proc sql.

  • a semicolon not required macro call (causes unexpected problems sometimes).

  • use %do %to loops

the code below should work.

data work.amostra;     input id;     cards; 1  4  7  10 ; run;  proc sql noprint;      select id :lista_id separated ' ' work.amostra;     select count(*) :nr separated ' ' work.amostra; quit;  * check; %put lista_id=&lista_id nr=&nr;  %macro ciclo_teste();     %local ref;     %do = 1 %to &nr;         %let ref = %scan(&lista_id, &i);          %*check;         %put ref = &ref;          /* task below */  /*        data work.up&ref;*/ /*            set work.base&ref;*/ /*            format perc_acum 9.3;*/ /*            if first.id_cliente perc_acum=0;*/ /*            perc_acum + perc;*/ /*        run; */     %end; %mend;  %ciclo_teste() 

tested on sas 9.4 win7 x64

edited:

in fact recommend doing avoid scanning long string inefficient.

%macro tester();     /* number of obs (a more efficient way) */     %local nn;     proc sql noprint;         select nobs :nn         dictionary.tables         upcase(libname) = 'work'              , upcase(memname) = 'amostra';     quit;      /* assign &ref random access */     %do = 1 %to &nn;         data _null_;             = &i;             set work.amostra point=a;             call symputx('ref',id,'l');             stop;         run;         %*check;         %put ref = &ref;          /* task below */     %end; %mend;  %tester() 

please let me know if have further questions.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -