Hello,
.So here's my issue: I've got a TABULATE procedure that gives me two variables called 2017 and 2018. The only thing is that this code needs to be flexible and used with initial data that isn't necessarily in 2017 or 2018 (it may be 2015 and 2016).
I've got two macro variables stored in another program called year and year_n1 which in this case are respectively 2018 and 2017.
In a PROC SQL, I need to rename these variables Year and YearN1.
Is there anyway I can do this so it works for any given period?
Thankssss
@polpel wrote:
Hello,
.So here's my issue: I've got a TABULATE procedure that gives me two variables called 2017 and 2018. The only thing is that this code needs to be flexible and used with initial data that isn't necessarily in 2017 or 2018 (it may be 2015 and 2016).
I've got two macro variables stored in another program called year and year_n1 which in this case are respectively 2018 and 2017.
Sure would be helpful to show us the code, and the data. The only way to write macros is to first have code that works for one or two instances WITHOUT macros and WITHOUT macro variables. Show us that working code for one or two instances without macros and without macro variables.
Also, you can't have "two variables called 2017 and 2018", these are not valid variable names. So a lot more detail is needed here.
@polpel wrote:
Hello,
.So here's my issue: I've got a TABULATE procedure that gives me two variables called 2017 and 2018.
Seriously doubt that Tabulate creates variables of those names. Possibly shows that as a value for a variable but the variables that Tabulate creates would have a statistic name suffixed to an existing variable.
If you have two variables that contain those values then you may be not using Proc Tabulate to the best advantage.
One might suspect that you are doing something related to dates but not actually using SAS date values then a proper format would display the dates with the year as wanted without playing around with variable names(?).
Code.
Example input data.
Where the 2017 and 2018 have to change to possibly 2015 and 2016.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: