BookmarkSubscribeRSS Feed
InêsMaximiano
Obsidian | Level 7

This is my current table:

Year Month Person Initial_Date Final_Date Unities Price Value
2024 1 Mary 01-01-2024 05-01-2024 7 30,28 1,000292
2024 1 Mary 06-01-2024 15-01-2024 7 30,28 1,000292
2024 1 Peter 05-01-2024 10-01-2024 13 122,54 3,00038
2024 1 Peter 11-01-2024 19-01-2024 13 122,54 3,00038

 

The number columns are the sum of the values for each Year/Month, but they are repeated because of the different columns Initial_Date and Final_Date.

 

I want the final result to have the values splited between the 2 rows instead of being repeated. Such as:

Year Month Person Initial_Date Final_Date Unities Price Value
2024 1 Mary 01-01-2024 05-01-2024 3 15,14 0,500146
2024 1 Mary 06-01-2024 15-01-2024 4 15,14 0,500146
2024 1 Peter 05-01-2024 10-01-2024 6 61,27 1,50019
2024 1 Peter 11-01-2024 19-01-2024 7 61,27 1,50019

 

How do I do this in SAS Data Integration Studio?

 

Thanks for the help

5 REPLIES 5
LinusH
Tourmaline | Level 20
So you want to split Price and Value in exactly halves, and Units halves rounded to the lower value for the first record (and upper for the second record)?
Not sure if this will depict "the truth", so you probably need to document this rule for data conumers.
From a data integrity perspective it would make more sense to merge the records instead, or try to find the original records that contributes to your numerival columns with date specifications.
That being said - there's not really an OOTB transformation for this, so probably a User Written data step is required. While doing so, make sure you use as many of the DI Studio generated macro variables in your code to make it more flexible and resilant for changes over time.
Data never sleeps
PaigeMiller
Diamond | Level 26

@InêsMaximiano wrote:

This is my current table:

Year Month Person Initial_Date Final_Date Unities Price Value
2024 1 Mary 01-01-2024 05-01-2024 7 30,28 1,000292
2024 1 Mary 06-01-2024 15-01-2024 7 30,28 1,000292
2024 1 Peter 05-01-2024 10-01-2024 13 122,54 3,00038
2024 1 Peter 11-01-2024 19-01-2024 13 122,54 3,00038

 

The number columns are the sum of the values for each Year/Month, but they are repeated because of the different columns Initial_Date and Final_Date.

 

I want the final result to have the values splited between the 2 rows instead of being repeated. Such as:

Year Month Person Initial_Date Final_Date Unities Price Value
2024 1 Mary 01-01-2024 05-01-2024 3 15,14 0,500146
2024 1 Mary 06-01-2024 15-01-2024 4 15,14 0,500146
2024 1 Peter 05-01-2024 10-01-2024 6 61,27 1,50019
2024 1 Peter 11-01-2024 19-01-2024 7 61,27 1,50019

 

How do I do this in SAS Data Integration Studio?

 

Thanks for the help


Are there ALWAYS two rows for each person? Can there ever be three (or more) rows for a person?

--
Paige Miller
InêsMaximiano
Obsidian | Level 7
The table has either one or two rows for each person. I need to fix it when we have two rows. There is never more than two rows for each person.
LinusH
Tourmaline | Level 20

"Skeleton" program, untested:

data &_OUTPUT.;
   set &_INPUT.;
   by year month person;
   if first.person and not last.person then do;
      price = price / 2;
      value = value / 2;
      unities = int(unities / 2);
   end;
   else if last.person and not first.person then do;
      price = price / 2;
      value = value / 2;
      unities = ceil(unities / 2);
   end;
run;
Data never sleeps
Patrick
Opal | Level 21

The solution @LinusH proposes should work for an implementation using DIS.

Why do you have to deal with such a source table in first place? Is this the result of some earlier SQL/group by aggregation where you potentially would need to add additional variables like initial_date and final_date to the grouping?

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 724 views
  • 0 likes
  • 4 in conversation