BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi, if someone can help me with this it would be greatly appreciated. I have a data that looks like:

jan-05 feb05 ... mar09 (by month along the columns)
a
b
c
d
...



The problem is say variable a first get data at feb05 so before that it would have all zeros, all the different variables starts getting non-zeros at different time.

How do i make this to a new dataset that has:

1st.month 2nd.month ...... x.month first24monthsum
a
b
c
d
...

So I can have each variable showing the first month it has data and onwards (so no leading zeros). And also a new column at the end that shows the sum of the first24month that it has data.

Thanks!!
5 REPLIES 5
deleted_user
Not applicable
Hi Proccontents,

Thanks for the reply, I was trying to do this:

What data looks like:

data test ;
Input Week $ J05 F05 M05 A05 ;
Datalines;
product1 12 0 0 2
product2 0 0 0 4
product3 0 7 0 5
product4 0 10 9 8
product5 0 50 20 0
Run;

Results:

data result ;
Input Week $ fristm secondm thirdm fourthm ;
Datalines;
product1 12 0 0 2
product2 4 0 0 0
product3 7 0 5 0
product4 10 9 8 0
product5 50 20 0 0
Run;

So I have this dataset that has different products and they each have different release month of when they go on the market. because my original dataset starts at J05 while some products release later (product5 releases in F05)
I want to make the data set so instead of the columns going JAN05 F05...
I want it to show 1st month of sales, 2nd month of sales for each product.

I hope this makes sense.

Thanks!
Flip
Fluorite | Level 6
Simple solution:

data test ;
Input Week $ J05 F05 M05 A05 ;
Datalines;
product1 12 0 0 2
product2 0 0 0 4
product3 0 7 0 5
product4 0 10 9 8
product5 0 50 20 0
Run;

data test1 (drop = J05 F05 M05 A05 i j) ;
set test ;
array inweek J05 F05 M05 A05 ;
array outweek wk1 - wk4;
do i = 1 to dim(inweek);
if inweek(i) ne 0 then do j = 1 to dim(inweek);
outweek(j) = inweek(i);
i + 1;
sumweek = sum(wk1-wk4);
if i > dim(inweek) then return;
end;
end;
run;
proc print;
run;
deleted_user
Not applicable
Thank you both so much!!

This is what I was looking for
deleted_user
Not applicable
Can you tell me what this line of code does?

if i > dim(inweek) then return;


Does this just mean that once it does the last one (in this case 4)
it will be 4+1 so it is now bigger than our inweek array of 4 so it stops the loop?

Thanks
Flip
Fluorite | Level 6
You might do it cleaner, but without it the loop was executing a reference to the array at a limit + 1 point and getting an error. This just forces the loop to end since you are not actually executing the upper end of the outer loop.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 738 views
  • 0 likes
  • 2 in conversation