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

Hi everyone,

 

I want to adjust a macro - here called MacroBL -, which was developed by someone else. For this macro to function, I need to write the variables that I want and separate them with an backslash (\). For each variable I need to write the name, type (CTN: continuous, or CTG: categorical) and label manually. There is no way for this macro to retrieve the variable's format.

 

What I have tried to do for the last six hours is to let the macro recognize the variable's label, format and type directly as present in the data. I tried several methods like using vlabelx, varlabel or %sysfunc(varlabel) but I didn't get it to work.

I am not a macro expert and the answer should be really easy. Do you guys have an idea?  Thanks in forward.

 

Here is the essential part of the macro I'm trying to manipulate.

 

%MacroBL(data=, var=var1|CTN|label1\ var2|CTG|label2)

%let nvar=%sysfunc(countw(&var,%str(\))); %do n=1 %to &nvar; %let var&n=%scan(%qscan(&var,&n,%str(\)),1,|); %let vartype&n=%scan(%qscan(&var,&n,%str(\)),2,|); %let varlabel&n=%scan(%qscan(&var,&n,%str(\)),3,|);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

You can get variable names, labels and formats from Dictionary.columns (or sashelp.vcolumn) given a library and dataset name.

Or with proc contents. But are you sure every variable has a format assigned? a Label?

 

And what information in the data set metadata tells you that a variable is categorical or continuous?

 

The following code creates a table of properties of the data set SASHELP.BASEBALL.

proc sql;
   create table work.properties as 
   select name, type,label,format
   from dictionary.columns
   where libname='SASHELP' and memname='BASEBALL';
quit;

Note the TYPE will be "char" or "num" in the resulting set. I don't know how to get CTN or CTG from these properties for this data set.

That might be sufficient with a data step using that information to create either an %include file with the call to the macro using that data set information, or Call execute

View solution in original post

1 REPLY 1
ballardw
Super User

You can get variable names, labels and formats from Dictionary.columns (or sashelp.vcolumn) given a library and dataset name.

Or with proc contents. But are you sure every variable has a format assigned? a Label?

 

And what information in the data set metadata tells you that a variable is categorical or continuous?

 

The following code creates a table of properties of the data set SASHELP.BASEBALL.

proc sql;
   create table work.properties as 
   select name, type,label,format
   from dictionary.columns
   where libname='SASHELP' and memname='BASEBALL';
quit;

Note the TYPE will be "char" or "num" in the resulting set. I don't know how to get CTN or CTG from these properties for this data set.

That might be sufficient with a data step using that information to create either an %include file with the call to the macro using that data set information, or Call execute

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1239 views
  • 3 likes
  • 2 in conversation