Help using Base SAS procedures

Wildcards in model statement?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

Wildcards in model statement?

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

Attachment

Accepted Solutions
Solution
‎07-07-2011 09:01 PM
Occasional Contributor
Posts: 11

Re: Wildcards in model statement?

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 Smiley Surprisedrderedvars 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


All Replies
Respected Advisor
Posts: 3,777

Wildcards in model statement?

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

Occasional Contributor
Posts: 11

Wildcards in model statement?

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

Respected Advisor
Posts: 3,777

Wildcards in model statement?

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".

Occasional Contributor
Posts: 11

Re: Wildcards in model statement?

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:

Respected Advisor
Posts: 3,777

Re: Wildcards in model statement?

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.

Frequent Contributor
Posts: 75

Re: Wildcards in model statement?

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: CACOVSmiley Happy 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

   

Occasional Contributor
Posts: 11

Re: Wildcards in model statement?

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.

Solution
‎07-07-2011 09:01 PM
Occasional Contributor
Posts: 11

Re: Wildcards in model statement?

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 Smiley Surprisedrderedvars 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.

Super User
Posts: 9,671

Re: Wildcards in model statement?

Did you try :

first_var_name -- last_var_name

Ksharp

Occasional Contributor
Posts: 11

Re: Wildcards in model statement?

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?

Attachment
Occasional Contributor
Posts: 11

Re: Wildcards in model statement?

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

Occasional Contributor
Posts: 11

Re: Wildcards in model statement?

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.

Attachment
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 12 replies
  • 790 views
  • 0 likes
  • 4 in conversation