BookmarkSubscribeRSS Feed
polpel
Fluorite | Level 6

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

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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

 

--
Paige Miller
ballardw
Super User

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

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

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 358 views
  • 0 likes
  • 3 in conversation