Sep-01-2019, 06:21 AM
Hi everyone,
I have a DF and I want to set an if statement in a function to sum a value if the first part of a field = '10'. This would be easy in SAS with the substr function. Can I do it in a dataframe or do I need to put it into an array and slice?
I have pasted the DF below, the column headers don't align well but you can make it out.
I hope that makes sense. Please let me know if you need more info.
Thanks
I have a DF and I want to set an if statement in a function to sum a value if the first part of a field = '10'. This would be easy in SAS with the substr function. Can I do it in a dataframe or do I need to put it into an array and slice?
I have pasted the DF below, the column headers don't align well but you can make it out.
Output: HSC Country Month Imports_(NZD) Harmonised System Description
0 101210015 New Zealand 201903 191,550 Horses; live, pure-bred breeding animals, thor...
1 101210015 New Zealand 201904 190,550 Horses; live, pure-bred breeding animals, thor...
2 101290010 New Zealand 201903 76,660 Horses; live, other than pure-bred breeding an...
3 101290010 New Zealand 201904 1,187,430 Horses; live, other than pure-bred breeding an...
4 101290013 New Zealand 201904 1,257,700 Horses; live, other than pure-bred breeding an...
What i want is an output with month as the index and then a new variable summed Import by is substr(hsc,0,2) = '01' which is grouped by month. I just want help with first variable and then I am going to create a few more summs based on the HSC that are grouped by month and have them as the new columns.I hope that makes sense. Please let me know if you need more info.
Thanks