BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rmlmrmlm
Obsidian | Level 7

Hello, good evening.

 

Imagine a dataset named DSet with one variable, that contains variable names:

 

-------------------

variable_name

-------------------

income

interest

result

 

I want to transform this variables to level=ordinal, one by one.

So, I wrote this code inside an extended node.
I must say that this is inside a diagram with a strong legacy. I didn't build it but now I'm must maintain it.

 

As you can see m, I'm mixing macro code with names of dataset variable names ...

This isn't working ... possibilby due to this mess ...  name = variable_name

 

Can somebody help me, please?

 

 

%macro test;

DATA _NULL_;

            SET DSet;

            %EM_METACHANGE (name = variable_name, level = ordinal);

RUN;

%mend test;

 

 

%test;

 

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
rogerjdeangelis
Barite | Level 11
DATA _NULL_;
   SET DSet;
   call symputx('variable_name',variable_name);
   call symputx('ordinal',variable_name);
     rc=dosubl('
            %EM_METACHANGE (name = &variable_name, level = &ordinal);
     ');
RUN;

View solution in original post

2 REPLIES 2
ballardw
Super User

 

If you are wanting to call an already existing macro with values from a data set then the approach is likely to be CALL EXECUTE.

Perhaps:

DATA _NULL_;
   SET DSet;
   Call execute( '%EM_METACHANGE (name ='|| variable_name||', level = ordinal);');
RUN;

This is one time you don't want the macro inside double quotes because it will attempt to execute while the data step compiles.

 

 

This assumes that you have an existing macro %EM_METACHANGE that works correctly if you run it manually with the values of the variable.

There is not need for Macro Test that I can see.

rogerjdeangelis
Barite | Level 11
DATA _NULL_;
   SET DSet;
   call symputx('variable_name',variable_name);
   call symputx('ordinal',variable_name);
     rc=dosubl('
            %EM_METACHANGE (name = &variable_name, level = &ordinal);
     ');
RUN;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1226 views
  • 1 like
  • 3 in conversation