Your SAS programs, embedded in web apps and elsewhere

proc tabulate APPEND in option OUT= ?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

proc tabulate APPEND in option OUT= ?

Hello
I wish in a PROC TABULATE add data outputs (OUT =) in an existing table, but keeping the data already present. Basically, to add the new data in the old table.

Is this possible? Is there an option to add in my OUT =?

Here's my code for my PROC TABULATE:

PROC TABULATE
DATA = WORK. OUT TABLEAU_GLOBAL_R6 IS WORK. TablesTABLEAU_R6;
 VAR delai_moyen;
 CLASS Type_Document / ORDER = UNFORMATTED MISSING;
 CLASS date_mois / ORDER = UNFORMATTED MISSING;
 TABLE / * ROW Statement * /.
  date_mois,
  * COLUMN Statement * /.
 (Type_Document =' ') *(delai_moyen * Mean={LABEL=""});
 ;
RUN;
RUN; QUIT;

A big thank you to you.


Accepted Solutions
Solution
‎04-26-2017 03:58 PM
Frequent Contributor
Posts: 93

Re: proc tabulate APPEND in option OUT= ?

In that case, I would save all of your result sets in its own library.  Then, I would query dictionary.tables to gather all of the names of your results, while using the into: function in the query to get all of the names of the tables, separated by a space.  Then, I would run a datastep to merge the datasets.  Like such:

PROC SQL;
SELECT MEMNAME INTO: NEWVAR SEPARATED BY " " FROM DICTIONARY.TABLES WHERE LIBNAME = 'MYLIBRARY';
QUIT; 

DATA ALLRESULTS;
SET ELIG.&NEWVAR;
RUN;

 

 

View solution in original post


All Replies
Frequent Contributor
Posts: 93

Re: proc tabulate APPEND in option OUT= ?

PROC SQL;
CREATE TABLE ALLRESULTS AS
SELECT * FROM TABLEAU_GLOBAL_R6
UNION ALL
SELECT * FROM TABLEAU_GLOBAL_R5
UNION ALL
SELECT * FROM TABLEAU_GLOBAL_R4;
QUIT;
Occasional Contributor
Posts: 5

Re: proc tabulate APPEND in option OUT= ?

Posted in reply to thomp7050
Thank for your answer Thomp7050,

But I have to throw my program every month, my output table name (ex: TablesTABLEAU_R6) will not change.

I didn't want to change my program every month ^^
Solution
‎04-26-2017 03:58 PM
Frequent Contributor
Posts: 93

Re: proc tabulate APPEND in option OUT= ?

In that case, I would save all of your result sets in its own library.  Then, I would query dictionary.tables to gather all of the names of your results, while using the into: function in the query to get all of the names of the tables, separated by a space.  Then, I would run a datastep to merge the datasets.  Like such:

PROC SQL;
SELECT MEMNAME INTO: NEWVAR SEPARATED BY " " FROM DICTIONARY.TABLES WHERE LIBNAME = 'MYLIBRARY';
QUIT; 

DATA ALLRESULTS;
SET ELIG.&NEWVAR;
RUN;

 

 

Occasional Contributor
Posts: 5

Re: proc tabulate APPEND in option OUT= ?

Posted in reply to thomp7050
This code helps me a lot,

in my library I have other tables that do not apply to this project. How to get only tables starting with "TablesTABLEAU*"? "

What does ELIG?

Thank you.
Frequent Contributor
Posts: 93

Re: proc tabulate APPEND in option OUT= ?

Elig is just the name of the library I was using.  You can use any library name.

 

In the where clause of the sql statement, you can search for tables WHERE MEMNAME LIKE 'TablesTABLEAU%';  That should do the trick.  OR just create another library with only your result sets.  Either way.

Occasional Contributor
Posts: 5

Re: proc tabulate APPEND in option OUT= ?

Thanks a lot it's work !!

Here my code :

PROC SQL;
SELECT compress(LIBNAME)||'.'||compress(MEMNAME) INTO: NEWVAR SEPARATED BY " "
FROM DICTIONARY.TABLES WHERE LIBNAME = 'TDB' and MEMNAME like 'TablesTABLEAU%';
QUIT;


DATA ALLRESULTS;
SET &NEWVAR;
RUN;

Have a good day all Smiley Wink
Community Manager
Posts: 406

Re: proc tabulate APPEND in option OUT= ?

Hi @PAULOM,

 

I unmarked your solution and marked @thomp7050's solution as correct, since that what you said helped you. Thanks for using the communities

 

Best,

Shelley

Super User
Posts: 11,343

Re: proc tabulate APPEND in option OUT= ?

Combining data from different tables is the same regardless of the source of the table. It isn't quite clear what you want by you could:

Combine the data with a datastep (set, merge or possibly update), proc sql join or possibly Proc append. However the OUT= option on proc tabulate will replace an existingd data set.

 

Note that you can create multiple table statements within a single call to proc tabulate and all of the resulting tables will be in the OUT= dataset and there is a variable to indicate which table the output is from.

 

Examples of what you need to combine would be helpful

Occasional Contributor
Posts: 5

Re: proc tabulate APPEND in option OUT= ?

What I want is very simple actually (I'm complicated can be too life):

every month I have to throw this proc tabulate that me returns an array and an output table, ex:

Type_document | date_moisdelai_moyen

ADC: 4-2017 | 12.5
ADP: 2017-4: 13

Because we are in the month of April

But in may I will:

ADC | 5-2017 | 15.5
ADP | 5-2017 | 13.6

So I want to in my table:

ADC: 4-2017 | 12.5
ADP: 2017-4: 13
ADC | 5-2017 | 15.5
ADP | 5-2017 | 13.6

So that I can use this table in a proc tabulate.

Thanks
Super User
Super User
Posts: 7,039

Re: proc tabulate APPEND in option OUT= ?

[ Edited ]

I would say the answer is NO. Just add another step to your program.

So if the goal is to append the reults from the proc tablulate that you just ran to a table named OUT.ALL_RUNS then you code will look like this.

proc tabulate out=todays_run ....
proc append base=out.all_runs data=todays_run; 
run;

But I expect you will have trouble with that if the variables that PROC TABULATE creates depends on the values in the input data. For PROC APPEND (or any type of insert into existing table operation) to work the base dataset needs to have all of the variables.

You might have better results generating a summary of the data using PROC SUMMARY. You could then use PROC TABULATE to produce a nice report from that summary data and also append the summary data to your existing dataset.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 233 views
  • 1 like
  • 5 in conversation