I would like to make changes to the following program in order to get 2 dataset, instead of 3, each dataset with two columns label1 and label2 containing respectively the strings ONE and TWO. I've seen around i can use catq and off course quote, but i can't figure out how.
%MACRO TEST;
%LET VAR1 = 'ONE';
%LET VAR2 = TWO;
DATA TEMP&VAR1. TEMP&VAR2.;
LABEL1 = &VAR1.;
LABEL2 = &VAR2.;
RUN;
%MEND;
%TEST;
Before you start using macros have working code (working= no errors, warnings and unexpected notes). Then ask yourself: is a macro really necessary? Does it reduce the amount of code required to solve an issue? If you can't say YES to both questions, stick to normal code.
When working with macros, enable the options mprint, mlogic and symbolgen. Then execute the code and read the log.
Some hints:
Another point: please avoid coding all upcase.
Please describe what you want to do by presenting test data in the form of a datastep, and what you want the output to look like. As noted there are various issues with the code. Also, is there a good reason to split one dataset to two - very rarely is this the case.
The code you presented actually does nothing more than:
data temp_one temp_two; label one "one" two "two"; run;
So the question is why that code at all, and in fact why the code full stop, as the datastep does nothing.
@arjunascagnetto wrote:
I would like to make changes to the following program in order to get 2 dataset, instead of 3, each dataset with two columns label1 and label2 containing respectively the strings ONE and TWO. I've seen around i can use catq and off course quote, but i can't figure out how.
%MACRO TEST;
%LET VAR1 = 'ONE';
%LET VAR2 = TWO;
DATA TEMP&VAR1. TEMP&VAR2.;
LABEL1 = &VAR1.;
LABEL2 = &VAR2.;
RUN;
%MEND;%TEST;
There is no CATQ function in SAS.
You have code that does nothing even if it were to work properly. You need to get the code working properly without macros FIRST (as others have pointed out) and then you might find out you don't need macros (which you don't) in this case.
it's related to a more complex problem. This is the summary of the problem. Please think about it as a proof of concept, not a real problem. Show me only how to get 2 dataset with two columns named label1 and label2 containing the strings ONE and TWO. Nothing else.
Well then, @arjunascagnetto, your summary is code that does nothing, and unnecessarily uses macros when no macros are needed, and so we cannot advise your further.
Can you show us the relevant parts of the more complex problem?
@arjunascagnetto wrote:
i know it does nothing it's just an example. I don't know if macros are realy useless. I'll show you something more similar to the problem.
I did not say macros are useless. I said they were unnecessary in the original example you showed.
I'll show you something more similar to the problem.
lista comes from a into statement inside a proc sql.
%MACRO SFOGLIAM;
%LET LEN=%SYSFUNC(COUNTW(&LISTA.,','));
%DO I=1 %TO &LEN.;
%LET VAR = %SCAN(&LISTA.,&I.,',');
DATA TEMP_&VAR.;
LABEL = &VAR.;
/* other code not relevant*/
RUN;
%END;
%MEND;
Clearly here there seems to be some value in have the macro variable &LISTA parsed and used, but again, we cannot help you with the original problem because you have not explained the original problem, other than showing us code that doesn't work and does nothing if it did work.
We are asking you to now clearly state the problem you face, and show us working code that does the job you want in a single instance. If we can see what the code does in a single instance, and we understand the problem, we can help you make the code dynamic by using macros, if that is the best solution (which it may not be).
Let's start with the original question. Given that it has value because it is a simplification of a more complex problem:
%macro test;
%let var1 = ONE;
%let var2 = TWO;
data temp&one temp&two;
label1 = "&var1";
label2 = "&var2";
run;
%mend test;
%test
Once you agree with that as a starting point, we can consider something that approaches real-life complexity.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.