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."

 

AI Navigator GIF.gif


Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.

Check it out on Microsoft Marketplace →

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