Macro that outputs table with testing results of SAS table

后端 未结 2 1172
野的像风
野的像风 2021-01-27 08:51

Problem

I\'m not a very experienced SAS user, but unfortunately the lab where I can access data is restricted to SAS. Also, I don\'t currently have access to the data

2条回答
  •  Happy的楠姐
    2021-01-27 09:00

    At the moment I can't open your simulated dataset but I can give you some advices, hope they will help.

    You can add the n extreme values of given variables using the 'output out=' statement with the option IDGROUP.

    Here an example using charity dataset ( run this to create it http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#p1oii7oi6k9gfxn19hxiiszb70ms.htm)

    proc means data=Charity;
       var MoneyRaised HoursVolunteered;
       output out=try sum=
       IDGROUP ( MAX (Moneyraised HoursVolunteered) OUT[2] (moneyraised hoursvolunteered)=max1 max2);
    run;
    data    var1 (keep=name1 _freq_ moneyraised max1_1 max1_2 rename=(moneyraised=value max1_1=largest max1_2=seclargest name1=name))
            var2 (keep=name2 _freq_ HoursVolunteered max2_1 max2_2 rename=(HoursVolunteered=value max2_1=largest max2_2=seclargest name2=name));
    length name1 name2 $4;
    set try ;
    name1='VAR1';
    name2='VAR2';
    run;
    
    data finalmerge;
    length flag $1;
    set var1 var2;
    if largest+seclargest > value*0.9 then flag='Y';
    run;
    

    in the proc means I choose to variables moneyraised and hoursvolunteered, you will choose your var1 var2 var3 and make your changes in all the program.

    The IDgroup will output the max value for both variables, as you see in the parentheses, but with out[2], obviously largest and second largest.

    You must rename them, I choose to rename max1 and max 2, then sas will add an _1 and _2 to the first and the second max values automatically.

    All the output will be on the same line, so I do a datastep referencing 2 datasets in output (data var1 var2) keeping the variables needed and renaming them for the next merge, I also choose a naming system as you see.

    Finally I'll merge the 2 datasets created and add the flag.

提交回复
热议问题