BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
acordes
Rhodochrosite | Level 12

My code works for 1 computed column, but I cannot manage to get a second column attached. 

@BrunoMueller , any idea?

 

My code is based on  

Example 7: Subsetting A Computed Column

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/proccas/p1ioxwkh6crvhrn1alvzokmxsuyr.htm 

 

data casuser.cars;
set sashelp.cars;
if horsepower le 340;
run;

%let casy1=cars;
%let liby1=casuser;


proc cas;

    simple.distinct result=dist /
        table={name="&casy1.", caslib="&liby1."};
    run;
    table.recordCount result=count /
        table={name="&casy1.", caslib="&liby1."};
    run;
    nrows=findtable(count)[1,1];
    computedcolumn=findtable(dist).
      compute({"n_rows", "number of rows", best12.}, nrows)
      [, {"Column", "ndistinct","nmiss", "n_rows"}];
    subset= computedcolumn; 

    saveresult subset dataout=work.&casy1.;
    run;

    simple.distinct result=dist /
        table={name="&casy1.", caslib="&liby1."};
    run;
    table.recordCount result=count /
        table={name="&casy1.", caslib="&liby1."};
    run;
    nrows=findtable(count)[1,1];
    computedcolumn=findtable(dist).
      compute({"filter", "filter criteria", $200.},  
                    "if horsepower le 340")
      [, {"Column", "ndistinct","nmiss", "filter"}];
    subset= computedcolumn; 

    saveresult subset dataout=work.filt_&casy1.;
    run;

    simple.distinct result=dist /
        table={name="&casy1.", caslib="&liby1."};
    run;
    table.recordCount result=count /
        table={name="&casy1.", caslib="&liby1."};
    run;
    nrows=findtable(count)[1,1];
    computedcolumn=findtable(dist).
      compute({{"n_rows", "number of rows", best12.}, nrows} ,
              {{"filter", "filter criteria", $200.},  
                    "if horsepower le 340" })
      [, {"Column", "ndistinct","nmiss", "n_rows", "filter"}];

    subset= computedcolumn; 

    saveresult subset dataout=work.&casy1._2cols;
    run;


run;
1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

Hi 

 

According to the doc (https://documentation.sas.com/doc/en/pgmsascdc/default/caslpg/p1xhd1xslkblfan16lcboym5nle9.htm) for the result table compute operator, it is only possible to have one column added. To add a second column you do need a second statement, see example below.

data casuser.cars;
set sashelp.cars;
if horsepower le 340;
run;

%let casy1=cars;
%let liby1=casuser;


proc cas;
    simple.distinct result=dist /
        table={name="&casy1.", caslib="&liby1."};
    run;
    table.recordCount result=count /
        table={name="&casy1.", caslib="&liby1."};
    run;
    nrows=findtable(count)[1,1];
    computedcolumn=findtable(dist).
      compute({"n_rows", "number of rows", best12.}, nrows);
    subset= computedcolumn; 
    saveresult subset dataout=work.&casy1.;
    print subset;
    run;
    computedColumn = computedColumn.compute(
      {"filter", "where clause", $4096.}, "make = 'Europe'"
      );
    print computedColumn;
    describe computedColumn;
run;
  saveresult computedColumn dataout=work.final ;
run;
quit;

View solution in original post

1 REPLY 1
BrunoMueller
SAS Super FREQ

Hi 

 

According to the doc (https://documentation.sas.com/doc/en/pgmsascdc/default/caslpg/p1xhd1xslkblfan16lcboym5nle9.htm) for the result table compute operator, it is only possible to have one column added. To add a second column you do need a second statement, see example below.

data casuser.cars;
set sashelp.cars;
if horsepower le 340;
run;

%let casy1=cars;
%let liby1=casuser;


proc cas;
    simple.distinct result=dist /
        table={name="&casy1.", caslib="&liby1."};
    run;
    table.recordCount result=count /
        table={name="&casy1.", caslib="&liby1."};
    run;
    nrows=findtable(count)[1,1];
    computedcolumn=findtable(dist).
      compute({"n_rows", "number of rows", best12.}, nrows);
    subset= computedcolumn; 
    saveresult subset dataout=work.&casy1.;
    print subset;
    run;
    computedColumn = computedColumn.compute(
      {"filter", "where clause", $4096.}, "make = 'Europe'"
      );
    print computedColumn;
    describe computedColumn;
run;
  saveresult computedColumn dataout=work.final ;
run;
quit;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 568 views
  • 1 like
  • 2 in conversation