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

Hello.

I'm trying to replicate the sample data below in Excel (Period + Have) to SAS, trying to calculate the product between periods (for period 1 = have1; for period 2 = have 1*have2; for period 3 = have1*have2*have3; etc.) or alternatively multiply the current period by the previous period (for period 1 = have1; for period 2 = have2*Or1; for period 3 = have 3*Or2; etc).

 

I've already tried with loops or with the product workaround available but I'm not getting the results I desire.

 

Is there someone who can help me please?

 

Many thanks.

 

Excel Sample:

PeriodHaveWantExcel FormulaOr Excel Formula
10,983734900,98373490 0,98373490=+B2
20,950775410,93531096=PRODUCT(B$2:B3)0,93531096=+B3*E2
30,922904040,86320226=PRODUCT(B$2:B4)0,86320226=+B4*E3
40,939525220,81100029=PRODUCT(B$2:B5)0,81100029=+B5*E4
50,968576110,78551551=PRODUCT(B$2:B6)0,78551551=+B6*E5
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

If I understand the problem correctly, SAS does this pretty easily:

data new;
   set old (keep=period have);
   retain want 1;
   want = want * have;
run;

When moving from Excel to SAS, you need to get used to the idea that SAS is processing a single row at a time. 

View solution in original post

4 REPLIES 4
Astounding
PROC Star

If I understand the problem correctly, SAS does this pretty easily:

data new;
   set old (keep=period have);
   retain want 1;
   want = want * have;
run;

When moving from Excel to SAS, you need to get used to the idea that SAS is processing a single row at a time. 

Jorge_Silva
Fluorite | Level 6
Hi.
Thanks a lot to both for your very quick answers. Both solutions work perfectly and solve my problem.
Best regards.
Rick_SAS
SAS Super FREQ

I used PROC FCMP to implement a PRODUCT function. The implementation also handles missing values. See "Implement a product function in SAS."

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 645 views
  • 4 likes
  • 4 in conversation