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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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