BookmarkSubscribeRSS Feed
meres
Calcite | Level 5

hay, i have some problem. i want to looping all macro, and expected output is i have 3 dataset output from proc freq (test_education ; test_residence and test_monthly_income)

but my code works for the last variable in macro %LET (monthly_income)..

is it possible to me if i want to automatically create 3 dataset in row.. how is it possible? is my sas code is wrong?

thanks

sorry for my bad english.. here i attach the code...

%macro infoid(data,xvar,yvar);

data _null_;

if 0 then set &data.;

array _x

  • &xvar;
  • array _y

  • &yvar;
  • call symput("nx", trim(left(put(dim(_x),12.))));

    call symput("ny", trim(left(put(dim(_y),12.))));

    length _mname _vname $20;

    do _i=1 to dim(_x);

    _mname='x'||trim(left(put(_i,12.)));

    call execute('%global '||_mname);

    call vname(_x[_i],_vname);

    call symput(_mname,trim(_vname));

    end;

    do _i=1 to dim(_y);

    _mname='y'||trim(left(put(_i,12.)));

    call execute('%global '||_mname);

    call vname(_y[_i],_vname);

    call symput(_mname,trim(_vname));

    end;

    stop;

    proc sort data=&data.(keep= &&x&nx gbi ) out=test_&&x&x;

    by &&x&nx;

    run;

    %mend;

    %let xvar = education_level residence monthly_income ;

    %infoid(&xvar,gbi);

    3 REPLIES 3
    LinusH
    Tourmaline | Level 20

    I'm confused, you have three parameters in the macro definition, but you only seem to use two of them, and I guess that your &xvar will be received as &data - is that what you want?

    Data never sleeps
    Tom
    Super User Tom
    Super User

    There is no actual macro loop coded in that macro.

    It looks like you want to put the PROC SORT step inside of a %DO loop.

    Amir
    PROC Star

    Hi,

    If I've understood your macro function definition it processes one data set only, so maybe you could call your macro 3 times, each time supplying the different data set name.

    To automatically loop through a space-separated list of data set names then you could use something like the following, based on code supplied by @Tom:

    %macro infoid_loop(datalist);

      %local i date ;

      %do i=1 %to %sysfunc(countw(&datalist,%str( )));

        %let dataset=%scan(&datalist,&i,%str( ));

        %infoid(&dataset,arg2,arg3);

      %end;

    %mend infoid_loop;


    Then invoke it:

    %infoid_loop(set_a set b set_c,arg2,arg3);

    One thing I noticed is that your macro function definition allows 3 parameters to be passed to it:

    %macro infoid(data,xvar,yvar);

    but you are only calling it with 2 parameters:

    %infoid(&xvar,gbi);

    If you are still having problems then please post the log with any error messages showing.

    Regards,

    Amir.

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