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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 364 views
  • 1 like
  • 2 in conversation