Help using Base SAS procedures

sas programming question

Reply
N/A
Posts: 0

sas programming question

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!!
N/A
Posts: 0

Re: sas programming question

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!
Super Contributor
Posts: 359

Re: sas programming question

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;
N/A
Posts: 0

Re: sas programming question

Thank you both so much!!

This is what I was looking for
N/A
Posts: 0

Re: sas programming question

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
Super Contributor
Posts: 359

Re: sas programming question

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.
Ask a Question
Discussion stats
  • 5 replies
  • 158 views
  • 0 likes
  • 2 in conversation