BookmarkSubscribeRSS Feed
ndee
Calcite | Level 5

Hello All,

 

I have a Product Sales Table currently and I need to load new values(column) called Annual Sales Projectioninto that table every 3 months. Below are the source tables and the desired table.

 

Product Sales Table:

Date                         Product                         Sales

01/01/2017                Pen                                100

01/01/2017                Book                              100

01/01/2017                Pencil                             100

02/01/2017                Pen                                400

02/01/2017                Book                              200

02/01/2017                Pencil                             400

03/01/2017                Pen                                 200

03/01/2017                Book                              100 

03/01/2017                Pencil                             200

04/01/2017                Pen                                 100

04/01/2017                Book                              400

04/01/2017                Pencil                             100

05/01/2017                Pen                                 400

05/01/2017                Book                              400

05/01/2017                Pencil                             400

06/01/2017                Pen                                 400

06/01/2017                Book                              400

06/01/2017                Pencil                             400

 

 

 

Annual Sales Projection:

 

Quarter 1:  01/01/2017     

                  02/01/2017    

                  03/01/2017

 

Pen  =   600

Book =     502                        

Pencil =    400

 

Quarter 2:  04/01/2017     

                  05/01/2017    

                  06/01/2017

 

Pen  =   3000

Book =     2000                        

Pencil =    5000

 

Desired table:

 

Date                         Product                         Sales                  Annual Sales Projection

01/01/2017                Pen                                100                                600

01/01/2017                Book                              100                                502

01/01/2017                Pencil                             100                               400

02/01/2017                Pen                                400                                600

02/01/2017                Book                              200                                502

02/01/2017                Pencil                             400                                400

03/01/2017                Pen                                 200                                600

03/01/2017                Book                              100                                 502

03/01/2017                Pencil                             200                                 400

04/01/2017                Pen                                 100                                 3000

04/01/2017                Book                              400                                  2000

04/01/2017                Pencil                             100                                  5000

05/01/2017                Pen                                 400                                 3000                            

05/01/2017                Book                              400                                   2000

05/01/2017                Pencil                             400                                  5000

06/01/2017                Pen                                 400                                  3000 

06/01/2017                Book                              400                                    2000

06/01/2017                Pencil                             400                                   5000

 

Basically, Annual Sales Projection changes every 3 months and I have to load those static values into the table. 

 

Any help will be greatly appreciated. 

 

Thank you.

3 REPLIES 3
Shmuel
Garnet | Level 18

It seems that you can either merge data - if both are sorted by date and product or 

do proc append of new quarter to the old/accumulated dataset and then sort by date and product.

novinosrin
Tourmaline | Level 20

Give the details of 

Annual Sales Projection table in a table format like the first table and not like notes. I am too lazy to type even for my own sake let alone others. Please

 

Quarter 1:  01/01/2017     

                  02/01/2017    

                  03/01/2017

 

Pen  =   600

Book =     502                        

Pencil =    400

 

Quarter 2:  04/01/2017     

                  05/01/2017    

                  06/01/2017

 

Pen  =   3000

Book =     2000                        

Pencil =    5000

novinosrin
Tourmaline | Level 20

@ndee Untested because you didn't provide the 2nd table AnnualSalesProjection in table format to easy copy paste

 

 

data want;
if _N_ = 1 then do;
if 0 then set  AnnualSalesProjection;
declare hash h(dataset:'AnnualSalesProjection',multidata:'y');
h.defineKey('quarter',);
h.defineData(all:'y');
h.defineDone();
end;
set ProductSalesTable;
array t(*) pen--pencil ;
if find(key:date)=0 then do;
do _n_=1 to dim(t);
if vname(t(_n_))=product then do;AnnualSalesProjection=t(_n_);leave;end;
end;
end;
else call missing(AnnualSalesProjection);
keep Date  Product    Sales AnnualSalesProjection;
run;

 

 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 3 replies
  • 785 views
  • 0 likes
  • 3 in conversation