BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
epialy
Calcite | Level 5

I seem to be stuck on something I thought would be quite simple but can't seem to get it to work as expected. I am trying to use the call symputx function which seems like it should be perfect for my need, but when attempting to store column values in a macro variable with this function I believe they may all be evaluating as missing?

 

I have arrays for DiseaseDate1-7 and MedicationDate1-41. I have a column, "x" which just has values missing (.),1, or 2. "x" reflects which DiseaseDate column I want to select (could have been up to 7 in theory, just happened to max out at 2). Basically, I am trying to run this line of code:

 

if (intck('days',DiseaseDate&n.,MedicationDate(_N_)) < 84) then NewVariable=1

_N_ is a do loop 1-41 and is resolving fine. It's the &n. I'm having trouble with. I tried call symputx('n',x) which as I understand should store the values of x but the log just keeps returning [Line generated by the macro variable "N"] DiseaseDate. so the macro variable n seems to only be populated with '.'

 

Not sure what I'm doing wrong here, any insight much appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@epialy wrote:

I seem to be stuck on something I thought would be quite simple but can't seem to get it to work as expected. I am trying to use the call symputx function which seems like it should be perfect for my need, but when attempting to store column values in a macro variable with this function I believe they may all be evaluating as missing?

 

I have arrays for DiseaseDate1-7 and MedicationDate1-41. I have a column, "x" which just has values missing (.),1, or 2. "x" reflects which DiseaseDate column I want to select (could have been up to 7 in theory, just happened to max out at 2). Basically, I am trying to run this line of code:

 

if (intck('days',DiseaseDate&n.,MedicationDate(_N_)) < 84) then NewVariable=1

_N_ is a do loop 1-41 and is resolving fine. It's the &n. I'm having trouble with. I tried call symputx('n',x) which as I understand should store the values of x but the log just keeps returning [Line generated by the macro variable "N"] DiseaseDate. so the macro variable n seems to only be populated with '.'

 

Not sure what I'm doing wrong here, any insight much appreciated.


Show your entire code and what you actually expect as output. Placing many values into macro variables is often either not needed or hard to maintain and use later. So a complete description of the entire problem is best. If possible provide some example data as well in the form of data step code.

 

Macro variables, such as your &n, use the value of the macro variable that is assigned when the data step compiles, so would not change in any iterations of the do loop. Why did you think that you needed a macro variable &n when you already have the variable X???

 

If you want to iterate over existing variable values then likely the approach would be to use an Array and that X variable when it is not missing. You don't show what to do if that x would be missing though. Something like:

array dd (*) diseasedate: ;
do _n_=1 to 41;
   /* assumes x has value of an appropriate index into the DD array*/
   if not missing(x) then if (intck('days',dd[x],MedicationDate(_N_)) < 84) then NewVariable=1;
end;

I tend to use the [ ] with arrays as a visual reminder that the item is an array index so it doesn't get confused with other function calls.

View solution in original post

2 REPLIES 2
ballardw
Super User

@epialy wrote:

I seem to be stuck on something I thought would be quite simple but can't seem to get it to work as expected. I am trying to use the call symputx function which seems like it should be perfect for my need, but when attempting to store column values in a macro variable with this function I believe they may all be evaluating as missing?

 

I have arrays for DiseaseDate1-7 and MedicationDate1-41. I have a column, "x" which just has values missing (.),1, or 2. "x" reflects which DiseaseDate column I want to select (could have been up to 7 in theory, just happened to max out at 2). Basically, I am trying to run this line of code:

 

if (intck('days',DiseaseDate&n.,MedicationDate(_N_)) < 84) then NewVariable=1

_N_ is a do loop 1-41 and is resolving fine. It's the &n. I'm having trouble with. I tried call symputx('n',x) which as I understand should store the values of x but the log just keeps returning [Line generated by the macro variable "N"] DiseaseDate. so the macro variable n seems to only be populated with '.'

 

Not sure what I'm doing wrong here, any insight much appreciated.


Show your entire code and what you actually expect as output. Placing many values into macro variables is often either not needed or hard to maintain and use later. So a complete description of the entire problem is best. If possible provide some example data as well in the form of data step code.

 

Macro variables, such as your &n, use the value of the macro variable that is assigned when the data step compiles, so would not change in any iterations of the do loop. Why did you think that you needed a macro variable &n when you already have the variable X???

 

If you want to iterate over existing variable values then likely the approach would be to use an Array and that X variable when it is not missing. You don't show what to do if that x would be missing though. Something like:

array dd (*) diseasedate: ;
do _n_=1 to 41;
   /* assumes x has value of an appropriate index into the DD array*/
   if not missing(x) then if (intck('days',dd[x],MedicationDate(_N_)) < 84) then NewVariable=1;
end;

I tend to use the [ ] with arrays as a visual reminder that the item is an array index so it doesn't get confused with other function calls.

epialy
Calcite | Level 5
Macro variables, such as your &n, use the value of the macro variable that is assigned when the data step compiles, so would not change in any iterations of the do loop. Why did you think that you needed a macro variable &n when you already have the variable X???

This made me realize that I was indeed massively overcomplicating this. I can just plug x and it totally works, I'm not sure why I thought I couldn't do that. It's been one of those days. Thanks!

 

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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
  • 1001 views
  • 0 likes
  • 2 in conversation