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

I'm using a macro that generates a separate variable for each level of a class variable (ex. ZLAND1 ZLAND2 ZLAND3 etc.). In my model statement, I want to use all of the variables with the same prefix, which seems best accomplished by a wildcard character (ex. ZLAND*). Is there a way to use wildcards in a model statement?

Thanks!Smiley Happy

1 ACCEPTED SOLUTION

Accepted Solutions
jmgorzo
Calcite | Level 5

Here is my workaround....

data interest;

keep ZLAND: CACOV: MCA: CASD: TCA: TCAI: CAD: AWMSI: MSI: MPFD: AWMPFD: CWED: TE: ED: MPS: NUMP: PSCOV: PSSD: TLA: CA:;

set classtrans;

run;

data narrowed;

drop CACV: MCAI: MCA1_: MSIE: MSID: ;

set interest;

run;

PROC CONTENTS DATA = NARROWED

OUT=VARlist(KEEP = NAME) NOPRINT;

RUN;

proc sql noprint;

select distinct name

into :orderedvars separated by ' '

from varlist;

quit;

This creates the macro variable &orderedvars. For some reason, though, I can't call that as an effect in proc glmselect model statement.

View solution in original post

12 REPLIES 12
data_null__
Jade | Level 19

Depends on the procedure but the proper syntax is name: as in ZLAND:.  But it may not be acceptable to MODEL statement.

jmgorzo
Calcite | Level 5

Indeed : does not work here as a wildcard. Any workaround fixes that come to mind if its impossible to use wildcard here?

data_null__
Jade | Level 19

An enumerated list might work ZLAND1-ZLAND3 or you can create a macro varible with the list of variables using PROC SQL.

proc sql noprint;

     select name into :zland separated by  ' '

        from dictionary.columns

        where libname eq 'WORK' and memname eq 'YOURDATASETNAME' and name eqT 'ZLAND';

   quit;

   run;

What PROC are you using you need to show more or you work cause you may be "working too hard".

jmgorzo
Calcite | Level 5

I attached the SAS program in the original post, here is one of the datasets I am working with. You can change the file path and run it if you want to see more of what I'm doing; I'm using proc glmselect. In the model statement I have all of the "prefixes" of the variables that I want to use out of the entire set, which are appended with class when transposed by the macro. You can proc print classtrans if you want to see what the macro output looks like :smileylaugh:

data_null__
Jade | Level 19

I don't think you sent all the required files but I'm not sure that would help.

I do wonder why you don't use the CLASS statement in GLMSELECT.

dhana
Fluorite | Level 6

Hi jmgorzo,

The problem can be solved in two ways...

1) Using Wildcard - When it comes to list of SAS variables, : (colon) can be used as a suffix wildcard.

    When a set of characters is followd by a colon in a variable list ( (ex. ZLAND: CACOV:) it implies that several variables are to be specified in the list.

2) Next is using Array  - Put all your wildcard variable list in an array and use array to list the variables in your code.

Hope this helps....! Smiley Happy

Thanks

Dhanasekaran R

   

jmgorzo
Calcite | Level 5

Apologies datanull, I forgot the response metric excel file, attached here. Class isn't a variable in the model, it is only used in the creation of those new variables. Dhana, thanks for the reply- as mentioned above, I am going to bold this so future readers do not miss it the colon does not work in the model statement unless I am using it incorrectly :smileysilly: If you have it working in a model statement in proc glmselect, please let me know. Array might work, I will try this but I am afraid it is going to consider the whole array as one variable, and my whole point of using the macro was to break up the variables. Perhaps I am wrong in how SAS will interpret it though.

jmgorzo
Calcite | Level 5

Here is my workaround....

data interest;

keep ZLAND: CACOV: MCA: CASD: TCA: TCAI: CAD: AWMSI: MSI: MPFD: AWMPFD: CWED: TE: ED: MPS: NUMP: PSCOV: PSSD: TLA: CA:;

set classtrans;

run;

data narrowed;

drop CACV: MCAI: MCA1_: MSIE: MSID: ;

set interest;

run;

PROC CONTENTS DATA = NARROWED

OUT=VARlist(KEEP = NAME) NOPRINT;

RUN;

proc sql noprint;

select distinct name

into :orderedvars separated by ' '

from varlist;

quit;

This creates the macro variable &orderedvars. For some reason, though, I can't call that as an effect in proc glmselect model statement.

Ksharp
Super User

Did you try :

first_var_name -- last_var_name

Ksharp

jmgorzo
Calcite | Level 5

I did not...I will give that a go. Now I have a new question though, may have to start a new thread. Here is the latest version of my project, replace coursefine.xls with the 1kmfine.xls listed above to run. I have picked out the variables I want to select from and manually put them in the model statementSmiley Wink However, it says no suitable observations were found when I run. When I run with way less variables, it will work...any ideas? What is the limitation here?

jmgorzo
Calcite | Level 5

Missing observations....fixed by running a bugged macro (I reported the error to SAS) to balance the observations. If you do this before they fix it, change that # to #

This macro removes variables that have any missing obs. All clear now!

http://support.sas.com/kb/24/613.html

jmgorzo
Calcite | Level 5

Here is my "variables fit to be considered" program. First reads my input excel file (use the one above to try, change pathname) then transposes all the variables by all the classes, so that each level of class represents a separate variable. Then deletes all variables with missing values (balances analysis). Then makes macro &orderedvars with all the variable names left.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 12 replies
  • 3806 views
  • 0 likes
  • 4 in conversation