'converting a SAS Macro to python with Pandas?
I'm converting a program of SAS code into a python equivalent. One section that i'm struggling with is how to convert a macro program in SAS when the variables used within the macro are used to create a dataset. for example:
Say my data has a column called type, and that takes either value of ‘tree’ or ‘bush’, I want to split my data in two, and then process the same functions on both and create separate output tables for both. In SAS this is quite simple. I write macros which are effectively functions that take my arguments and drop them into the code, making them unique datasets.
%macro program(type);
data portfolio_&type.;
set portfolio (where=(type=&type.));
run;
Proc freq data=Portfolio_&type.;
Tables var1 var2/out=summary_&type.;
Run;
%mend;
%program(Tree);
%program(bush);
The & allows me to drop my text into the dataset name but I can’t do this with a def function type statement in python because I can’t drop the argument into my data frame name
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|