SAS: using first. last. in %if in %macro










1















I am trying to build bins for numeric variables.
Everything worked fine when I haven't used %macro therefore I believe it's something macro specific. Basically this part of code:



%if first.&rank_column. = 1 %then %do;


doesn't work as I anticipated. Below I simplified to just one iteration and one variable but my actual code have many more - however the problem is the same.



Full code:



/* Build binns */
%let var_list = MSRP Invoice;

%macro group_var_in_bins(source_table);

data WITH_BINNS;
set &source_table.;
run;

%let loop_count = %sysfunc(countw(&var_list));

%do i=1 %to &loop_count.;

* list of variables to use;
%let variable = %scan(&var_list, &i);
%let rank_column = &variable._bins_rank;

proc rank data=WITH_BINNS out=WITH_BINNS groups=10 ties=low;
var &variable.;
ranks &rank_column.;
run;

* sort the table by this variable;
proc sort data=WITH_BINNS out=WITH_BINNS;
by &variable.;
run;

* Build start and end observation of particular bin;
data WITH_BINNS;

set WITH_BINNS;

by &rank_column.;

*this is just to check if first.&rank_column works;
first_&rank_column. = first.&rank_column.;
last_&rank_column. = last.&rank_column.;

%if first.&rank_column. = 1 %then %do;
/* here %if first.&rank_column. %then %do erros so something is wrong with argument statement*/
Start_bin = &variable.;
%end;
%else %do;
Start_bin = .;
%end;

%if last.&rank_column. = 1 %then %do;
End_bin = &variable.;
%end;
%else %do;
End_bin = .;
%end;

run;
%end;

* some more code which amends WITH_BINNS table;

%mend group_var_in_bins;

%group_var_in_bins(sashelp.cars);


The result is as:
enter image description here



so the loop doesn't recognize argument in %if part.



Thanks for help!!



[Edit]:



To clarify, steps I want to do are:



  1. for variable in list &var_list.


  2. build a rank for it


  3. sort by that variable


  4. using data step by: group by rank


  5. find the value of this variable which corresponds to beggining of group using first. and end end of group using last. leave the rest empty


  6. some next steps...


So basically I want to create begging and end of rank interval.



I example from picture; the first row has first. = 1 therefore Start_bin should e $10.280 and End_bin should be empty. The next row should be empty because both first. and last. are 0.










share|improve this question



















  • 1





    You probably want to use if, not %if.

    – Hong Ooi
    Nov 12 '18 at 17:10






  • 1





    You use macro logic to conditionally generate code. Why do you think you need to conditionally generate code? If you just want to execute different statements based on a condition then use a if statement. That will be able to see data step variables like the first. variables generated when you use a by statement.

    – Tom
    Nov 12 '18 at 17:18











  • If you want help solving your real problem then provide a description of what you are trying to do and give some example input data and the desired results.

    – Tom
    Nov 12 '18 at 17:19











  • hi @Tom I've used sashelp.cars so you could replicate my example. and added the steps I am doing and the result I want to achieve. I hope this clarifies.

    – Mateusz Konopelski
    Nov 12 '18 at 17:42






  • 1





    %if is for macro conditional logic to control what code your macro generates. You still use if and where for data conditional operations. Macros just generate SAS code, so they need to generate valid SAS code.

    – Tom
    Nov 12 '18 at 18:06
















1















I am trying to build bins for numeric variables.
Everything worked fine when I haven't used %macro therefore I believe it's something macro specific. Basically this part of code:



%if first.&rank_column. = 1 %then %do;


doesn't work as I anticipated. Below I simplified to just one iteration and one variable but my actual code have many more - however the problem is the same.



Full code:



/* Build binns */
%let var_list = MSRP Invoice;

%macro group_var_in_bins(source_table);

data WITH_BINNS;
set &source_table.;
run;

%let loop_count = %sysfunc(countw(&var_list));

%do i=1 %to &loop_count.;

* list of variables to use;
%let variable = %scan(&var_list, &i);
%let rank_column = &variable._bins_rank;

proc rank data=WITH_BINNS out=WITH_BINNS groups=10 ties=low;
var &variable.;
ranks &rank_column.;
run;

* sort the table by this variable;
proc sort data=WITH_BINNS out=WITH_BINNS;
by &variable.;
run;

* Build start and end observation of particular bin;
data WITH_BINNS;

set WITH_BINNS;

by &rank_column.;

*this is just to check if first.&rank_column works;
first_&rank_column. = first.&rank_column.;
last_&rank_column. = last.&rank_column.;

%if first.&rank_column. = 1 %then %do;
/* here %if first.&rank_column. %then %do erros so something is wrong with argument statement*/
Start_bin = &variable.;
%end;
%else %do;
Start_bin = .;
%end;

%if last.&rank_column. = 1 %then %do;
End_bin = &variable.;
%end;
%else %do;
End_bin = .;
%end;

run;
%end;

* some more code which amends WITH_BINNS table;

%mend group_var_in_bins;

%group_var_in_bins(sashelp.cars);


The result is as:
enter image description here



so the loop doesn't recognize argument in %if part.



Thanks for help!!



[Edit]:



To clarify, steps I want to do are:



  1. for variable in list &var_list.


  2. build a rank for it


  3. sort by that variable


  4. using data step by: group by rank


  5. find the value of this variable which corresponds to beggining of group using first. and end end of group using last. leave the rest empty


  6. some next steps...


So basically I want to create begging and end of rank interval.



I example from picture; the first row has first. = 1 therefore Start_bin should e $10.280 and End_bin should be empty. The next row should be empty because both first. and last. are 0.










share|improve this question



















  • 1





    You probably want to use if, not %if.

    – Hong Ooi
    Nov 12 '18 at 17:10






  • 1





    You use macro logic to conditionally generate code. Why do you think you need to conditionally generate code? If you just want to execute different statements based on a condition then use a if statement. That will be able to see data step variables like the first. variables generated when you use a by statement.

    – Tom
    Nov 12 '18 at 17:18











  • If you want help solving your real problem then provide a description of what you are trying to do and give some example input data and the desired results.

    – Tom
    Nov 12 '18 at 17:19











  • hi @Tom I've used sashelp.cars so you could replicate my example. and added the steps I am doing and the result I want to achieve. I hope this clarifies.

    – Mateusz Konopelski
    Nov 12 '18 at 17:42






  • 1





    %if is for macro conditional logic to control what code your macro generates. You still use if and where for data conditional operations. Macros just generate SAS code, so they need to generate valid SAS code.

    – Tom
    Nov 12 '18 at 18:06














1












1








1








I am trying to build bins for numeric variables.
Everything worked fine when I haven't used %macro therefore I believe it's something macro specific. Basically this part of code:



%if first.&rank_column. = 1 %then %do;


doesn't work as I anticipated. Below I simplified to just one iteration and one variable but my actual code have many more - however the problem is the same.



Full code:



/* Build binns */
%let var_list = MSRP Invoice;

%macro group_var_in_bins(source_table);

data WITH_BINNS;
set &source_table.;
run;

%let loop_count = %sysfunc(countw(&var_list));

%do i=1 %to &loop_count.;

* list of variables to use;
%let variable = %scan(&var_list, &i);
%let rank_column = &variable._bins_rank;

proc rank data=WITH_BINNS out=WITH_BINNS groups=10 ties=low;
var &variable.;
ranks &rank_column.;
run;

* sort the table by this variable;
proc sort data=WITH_BINNS out=WITH_BINNS;
by &variable.;
run;

* Build start and end observation of particular bin;
data WITH_BINNS;

set WITH_BINNS;

by &rank_column.;

*this is just to check if first.&rank_column works;
first_&rank_column. = first.&rank_column.;
last_&rank_column. = last.&rank_column.;

%if first.&rank_column. = 1 %then %do;
/* here %if first.&rank_column. %then %do erros so something is wrong with argument statement*/
Start_bin = &variable.;
%end;
%else %do;
Start_bin = .;
%end;

%if last.&rank_column. = 1 %then %do;
End_bin = &variable.;
%end;
%else %do;
End_bin = .;
%end;

run;
%end;

* some more code which amends WITH_BINNS table;

%mend group_var_in_bins;

%group_var_in_bins(sashelp.cars);


The result is as:
enter image description here



so the loop doesn't recognize argument in %if part.



Thanks for help!!



[Edit]:



To clarify, steps I want to do are:



  1. for variable in list &var_list.


  2. build a rank for it


  3. sort by that variable


  4. using data step by: group by rank


  5. find the value of this variable which corresponds to beggining of group using first. and end end of group using last. leave the rest empty


  6. some next steps...


So basically I want to create begging and end of rank interval.



I example from picture; the first row has first. = 1 therefore Start_bin should e $10.280 and End_bin should be empty. The next row should be empty because both first. and last. are 0.










share|improve this question
















I am trying to build bins for numeric variables.
Everything worked fine when I haven't used %macro therefore I believe it's something macro specific. Basically this part of code:



%if first.&rank_column. = 1 %then %do;


doesn't work as I anticipated. Below I simplified to just one iteration and one variable but my actual code have many more - however the problem is the same.



Full code:



/* Build binns */
%let var_list = MSRP Invoice;

%macro group_var_in_bins(source_table);

data WITH_BINNS;
set &source_table.;
run;

%let loop_count = %sysfunc(countw(&var_list));

%do i=1 %to &loop_count.;

* list of variables to use;
%let variable = %scan(&var_list, &i);
%let rank_column = &variable._bins_rank;

proc rank data=WITH_BINNS out=WITH_BINNS groups=10 ties=low;
var &variable.;
ranks &rank_column.;
run;

* sort the table by this variable;
proc sort data=WITH_BINNS out=WITH_BINNS;
by &variable.;
run;

* Build start and end observation of particular bin;
data WITH_BINNS;

set WITH_BINNS;

by &rank_column.;

*this is just to check if first.&rank_column works;
first_&rank_column. = first.&rank_column.;
last_&rank_column. = last.&rank_column.;

%if first.&rank_column. = 1 %then %do;
/* here %if first.&rank_column. %then %do erros so something is wrong with argument statement*/
Start_bin = &variable.;
%end;
%else %do;
Start_bin = .;
%end;

%if last.&rank_column. = 1 %then %do;
End_bin = &variable.;
%end;
%else %do;
End_bin = .;
%end;

run;
%end;

* some more code which amends WITH_BINNS table;

%mend group_var_in_bins;

%group_var_in_bins(sashelp.cars);


The result is as:
enter image description here



so the loop doesn't recognize argument in %if part.



Thanks for help!!



[Edit]:



To clarify, steps I want to do are:



  1. for variable in list &var_list.


  2. build a rank for it


  3. sort by that variable


  4. using data step by: group by rank


  5. find the value of this variable which corresponds to beggining of group using first. and end end of group using last. leave the rest empty


  6. some next steps...


So basically I want to create begging and end of rank interval.



I example from picture; the first row has first. = 1 therefore Start_bin should e $10.280 and End_bin should be empty. The next row should be empty because both first. and last. are 0.







sas sas-macro






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 17:41







Mateusz Konopelski

















asked Nov 12 '18 at 16:59









Mateusz KonopelskiMateusz Konopelski

183112




183112







  • 1





    You probably want to use if, not %if.

    – Hong Ooi
    Nov 12 '18 at 17:10






  • 1





    You use macro logic to conditionally generate code. Why do you think you need to conditionally generate code? If you just want to execute different statements based on a condition then use a if statement. That will be able to see data step variables like the first. variables generated when you use a by statement.

    – Tom
    Nov 12 '18 at 17:18











  • If you want help solving your real problem then provide a description of what you are trying to do and give some example input data and the desired results.

    – Tom
    Nov 12 '18 at 17:19











  • hi @Tom I've used sashelp.cars so you could replicate my example. and added the steps I am doing and the result I want to achieve. I hope this clarifies.

    – Mateusz Konopelski
    Nov 12 '18 at 17:42






  • 1





    %if is for macro conditional logic to control what code your macro generates. You still use if and where for data conditional operations. Macros just generate SAS code, so they need to generate valid SAS code.

    – Tom
    Nov 12 '18 at 18:06













  • 1





    You probably want to use if, not %if.

    – Hong Ooi
    Nov 12 '18 at 17:10






  • 1





    You use macro logic to conditionally generate code. Why do you think you need to conditionally generate code? If you just want to execute different statements based on a condition then use a if statement. That will be able to see data step variables like the first. variables generated when you use a by statement.

    – Tom
    Nov 12 '18 at 17:18











  • If you want help solving your real problem then provide a description of what you are trying to do and give some example input data and the desired results.

    – Tom
    Nov 12 '18 at 17:19











  • hi @Tom I've used sashelp.cars so you could replicate my example. and added the steps I am doing and the result I want to achieve. I hope this clarifies.

    – Mateusz Konopelski
    Nov 12 '18 at 17:42






  • 1





    %if is for macro conditional logic to control what code your macro generates. You still use if and where for data conditional operations. Macros just generate SAS code, so they need to generate valid SAS code.

    – Tom
    Nov 12 '18 at 18:06








1




1





You probably want to use if, not %if.

– Hong Ooi
Nov 12 '18 at 17:10





You probably want to use if, not %if.

– Hong Ooi
Nov 12 '18 at 17:10




1




1





You use macro logic to conditionally generate code. Why do you think you need to conditionally generate code? If you just want to execute different statements based on a condition then use a if statement. That will be able to see data step variables like the first. variables generated when you use a by statement.

– Tom
Nov 12 '18 at 17:18





You use macro logic to conditionally generate code. Why do you think you need to conditionally generate code? If you just want to execute different statements based on a condition then use a if statement. That will be able to see data step variables like the first. variables generated when you use a by statement.

– Tom
Nov 12 '18 at 17:18













If you want help solving your real problem then provide a description of what you are trying to do and give some example input data and the desired results.

– Tom
Nov 12 '18 at 17:19





If you want help solving your real problem then provide a description of what you are trying to do and give some example input data and the desired results.

– Tom
Nov 12 '18 at 17:19













hi @Tom I've used sashelp.cars so you could replicate my example. and added the steps I am doing and the result I want to achieve. I hope this clarifies.

– Mateusz Konopelski
Nov 12 '18 at 17:42





hi @Tom I've used sashelp.cars so you could replicate my example. and added the steps I am doing and the result I want to achieve. I hope this clarifies.

– Mateusz Konopelski
Nov 12 '18 at 17:42




1




1





%if is for macro conditional logic to control what code your macro generates. You still use if and where for data conditional operations. Macros just generate SAS code, so they need to generate valid SAS code.

– Tom
Nov 12 '18 at 18:06






%if is for macro conditional logic to control what code your macro generates. You still use if and where for data conditional operations. Macros just generate SAS code, so they need to generate valid SAS code.

– Tom
Nov 12 '18 at 18:06













2 Answers
2






active

oldest

votes


















1














So your basic problem is you are using macro logic where you should be using normal logic.



%if first.&rank_column. = 1 %then %do;


Will never be true, even if rank_column is empty because the string first. can never equal the string 1.



But if you code it using SAS code instead of macro code



if first.&rank_column. = 1 then do;


Then it will be true when you are on the first observation in that particular value of the variable named by the value of the macro variable rank_column.



You probably have bigger problems with your overall logic because you are overwriting the same variable names start_bin and end_bin in the same dataset. So only the values for the bins generated by the last variable your list will be available after the macro has finished.






share|improve this answer

























  • regarding start_bin and end_bin -> they are just temp variables used later to create the actual ones I wan to keep in WITH_BINNS table. Therefore they can be overwrite. Regarding everything else - you are right. I corrected my code and it's working like magic. thank you!

    – Mateusz Konopelski
    Nov 12 '18 at 19:06


















1














If you're ultimately looking for the bin boundaries, with groups=10, wouldn't that be equivalent to finding the percentiles via proc summary or proc means? The benefit of doing via percentiles method also means you can handle multiple variables at once. I didn't set any tie options here, but that can also be set I believe.



ods select none; /*do not display output - faster processing*/
proc means data=sashelp.cars /*input data set*/
stackods /*stack ods to have the table appear with statistics across the top*/
N NMISS Min P10 P20 P30 P40 P50 P60 P70 P80 P90 Max /*stats to show*/;
var mpg_city mpg_highway invoice msrp; /*variables included in analysis*/
ods output summary = want; /*capture output into a data set*/
run;
ods select all; /*reset output options*/





share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266816%2fsas-using-first-last-in-if-in-macro%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    So your basic problem is you are using macro logic where you should be using normal logic.



    %if first.&rank_column. = 1 %then %do;


    Will never be true, even if rank_column is empty because the string first. can never equal the string 1.



    But if you code it using SAS code instead of macro code



    if first.&rank_column. = 1 then do;


    Then it will be true when you are on the first observation in that particular value of the variable named by the value of the macro variable rank_column.



    You probably have bigger problems with your overall logic because you are overwriting the same variable names start_bin and end_bin in the same dataset. So only the values for the bins generated by the last variable your list will be available after the macro has finished.






    share|improve this answer

























    • regarding start_bin and end_bin -> they are just temp variables used later to create the actual ones I wan to keep in WITH_BINNS table. Therefore they can be overwrite. Regarding everything else - you are right. I corrected my code and it's working like magic. thank you!

      – Mateusz Konopelski
      Nov 12 '18 at 19:06















    1














    So your basic problem is you are using macro logic where you should be using normal logic.



    %if first.&rank_column. = 1 %then %do;


    Will never be true, even if rank_column is empty because the string first. can never equal the string 1.



    But if you code it using SAS code instead of macro code



    if first.&rank_column. = 1 then do;


    Then it will be true when you are on the first observation in that particular value of the variable named by the value of the macro variable rank_column.



    You probably have bigger problems with your overall logic because you are overwriting the same variable names start_bin and end_bin in the same dataset. So only the values for the bins generated by the last variable your list will be available after the macro has finished.






    share|improve this answer

























    • regarding start_bin and end_bin -> they are just temp variables used later to create the actual ones I wan to keep in WITH_BINNS table. Therefore they can be overwrite. Regarding everything else - you are right. I corrected my code and it's working like magic. thank you!

      – Mateusz Konopelski
      Nov 12 '18 at 19:06













    1












    1








    1







    So your basic problem is you are using macro logic where you should be using normal logic.



    %if first.&rank_column. = 1 %then %do;


    Will never be true, even if rank_column is empty because the string first. can never equal the string 1.



    But if you code it using SAS code instead of macro code



    if first.&rank_column. = 1 then do;


    Then it will be true when you are on the first observation in that particular value of the variable named by the value of the macro variable rank_column.



    You probably have bigger problems with your overall logic because you are overwriting the same variable names start_bin and end_bin in the same dataset. So only the values for the bins generated by the last variable your list will be available after the macro has finished.






    share|improve this answer















    So your basic problem is you are using macro logic where you should be using normal logic.



    %if first.&rank_column. = 1 %then %do;


    Will never be true, even if rank_column is empty because the string first. can never equal the string 1.



    But if you code it using SAS code instead of macro code



    if first.&rank_column. = 1 then do;


    Then it will be true when you are on the first observation in that particular value of the variable named by the value of the macro variable rank_column.



    You probably have bigger problems with your overall logic because you are overwriting the same variable names start_bin and end_bin in the same dataset. So only the values for the bins generated by the last variable your list will be available after the macro has finished.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 12 '18 at 19:57

























    answered Nov 12 '18 at 18:27









    TomTom

    22.8k2718




    22.8k2718












    • regarding start_bin and end_bin -> they are just temp variables used later to create the actual ones I wan to keep in WITH_BINNS table. Therefore they can be overwrite. Regarding everything else - you are right. I corrected my code and it's working like magic. thank you!

      – Mateusz Konopelski
      Nov 12 '18 at 19:06

















    • regarding start_bin and end_bin -> they are just temp variables used later to create the actual ones I wan to keep in WITH_BINNS table. Therefore they can be overwrite. Regarding everything else - you are right. I corrected my code and it's working like magic. thank you!

      – Mateusz Konopelski
      Nov 12 '18 at 19:06
















    regarding start_bin and end_bin -> they are just temp variables used later to create the actual ones I wan to keep in WITH_BINNS table. Therefore they can be overwrite. Regarding everything else - you are right. I corrected my code and it's working like magic. thank you!

    – Mateusz Konopelski
    Nov 12 '18 at 19:06





    regarding start_bin and end_bin -> they are just temp variables used later to create the actual ones I wan to keep in WITH_BINNS table. Therefore they can be overwrite. Regarding everything else - you are right. I corrected my code and it's working like magic. thank you!

    – Mateusz Konopelski
    Nov 12 '18 at 19:06













    1














    If you're ultimately looking for the bin boundaries, with groups=10, wouldn't that be equivalent to finding the percentiles via proc summary or proc means? The benefit of doing via percentiles method also means you can handle multiple variables at once. I didn't set any tie options here, but that can also be set I believe.



    ods select none; /*do not display output - faster processing*/
    proc means data=sashelp.cars /*input data set*/
    stackods /*stack ods to have the table appear with statistics across the top*/
    N NMISS Min P10 P20 P30 P40 P50 P60 P70 P80 P90 Max /*stats to show*/;
    var mpg_city mpg_highway invoice msrp; /*variables included in analysis*/
    ods output summary = want; /*capture output into a data set*/
    run;
    ods select all; /*reset output options*/





    share|improve this answer



























      1














      If you're ultimately looking for the bin boundaries, with groups=10, wouldn't that be equivalent to finding the percentiles via proc summary or proc means? The benefit of doing via percentiles method also means you can handle multiple variables at once. I didn't set any tie options here, but that can also be set I believe.



      ods select none; /*do not display output - faster processing*/
      proc means data=sashelp.cars /*input data set*/
      stackods /*stack ods to have the table appear with statistics across the top*/
      N NMISS Min P10 P20 P30 P40 P50 P60 P70 P80 P90 Max /*stats to show*/;
      var mpg_city mpg_highway invoice msrp; /*variables included in analysis*/
      ods output summary = want; /*capture output into a data set*/
      run;
      ods select all; /*reset output options*/





      share|improve this answer

























        1












        1








        1







        If you're ultimately looking for the bin boundaries, with groups=10, wouldn't that be equivalent to finding the percentiles via proc summary or proc means? The benefit of doing via percentiles method also means you can handle multiple variables at once. I didn't set any tie options here, but that can also be set I believe.



        ods select none; /*do not display output - faster processing*/
        proc means data=sashelp.cars /*input data set*/
        stackods /*stack ods to have the table appear with statistics across the top*/
        N NMISS Min P10 P20 P30 P40 P50 P60 P70 P80 P90 Max /*stats to show*/;
        var mpg_city mpg_highway invoice msrp; /*variables included in analysis*/
        ods output summary = want; /*capture output into a data set*/
        run;
        ods select all; /*reset output options*/





        share|improve this answer













        If you're ultimately looking for the bin boundaries, with groups=10, wouldn't that be equivalent to finding the percentiles via proc summary or proc means? The benefit of doing via percentiles method also means you can handle multiple variables at once. I didn't set any tie options here, but that can also be set I believe.



        ods select none; /*do not display output - faster processing*/
        proc means data=sashelp.cars /*input data set*/
        stackods /*stack ods to have the table appear with statistics across the top*/
        N NMISS Min P10 P20 P30 P40 P50 P60 P70 P80 P90 Max /*stats to show*/;
        var mpg_city mpg_highway invoice msrp; /*variables included in analysis*/
        ods output summary = want; /*capture output into a data set*/
        run;
        ods select all; /*reset output options*/






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 '18 at 20:15









        ReezaReeza

        13.1k21226




        13.1k21226



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266816%2fsas-using-first-last-in-if-in-macro%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

            Syphilis

            Darth Vader #20