BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PAULOM
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
thomp7050
Pyrite | Level 9

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

10 REPLIES 10
thomp7050
Pyrite | Level 9
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;
PAULOM
Calcite | Level 5
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 ^^
thomp7050
Pyrite | Level 9

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;

 

 

PAULOM
Calcite | Level 5
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.
thomp7050
Pyrite | Level 9

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.

PAULOM
Calcite | Level 5
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 😉
ShelleySessoms
Community Manager

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

ballardw
Super User

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

PAULOM
Calcite | Level 5
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
Tom
Super User Tom
Super User

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 10 replies
  • 2252 views
  • 1 like
  • 5 in conversation