Desktop productivity for business analysts and programmers

Macro to contain list of variable names

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Macro to contain list of variable names

Hi,

I am a noob concerning SAS programming. I came across a clustering method that i am applying to some sample data. I need a macro to contain a list of variable names and each time i call it it brings them, like a vector of some sort. Anyone keen on macro programming?

Here is the pdf i found with the clustering technique(http://support.sas.com/resources/papers/proceedings13/068-2013.pdf), in page 4 it says :

"The macros all_name and sm_name refer to the list of the variables of product frequencies and

the corresponding list of variables to be standardized (preceded by SM_), respectively"

Any help is welcome.

Thank you. Gd day to ye !


Accepted Solutions
Solution
‎05-13-2013 11:31 AM
Super Contributor
Posts: 543

Re: Macro to contain list of variable names

Hi.

Would something like this work?

(I am using sashelp.class)

*select the variable names once in the list all_name then in sm_name  - to be later used for standardization

proc sql;

    select name, compress("sm_" ||name) into: all_name separated by " ",

                : sm_name separated by " "

    from dictionary.columns

    where libname = "SASHELP" & memname = "CLASS" & name not in ("Name", "Sex");

quit;

data temp;

set sashelp.class ;

keep &all_name. &sm_name. name ;

array  avar {*} &all_name. ;

array  svar {*} &sm_name. ;

do i = 1 to dim(avar);

    svar(i) = avar(i);

end;

run;

Good luck!

Anca.

View solution in original post


All Replies
Solution
‎05-13-2013 11:31 AM
Super Contributor
Posts: 543

Re: Macro to contain list of variable names

Hi.

Would something like this work?

(I am using sashelp.class)

*select the variable names once in the list all_name then in sm_name  - to be later used for standardization

proc sql;

    select name, compress("sm_" ||name) into: all_name separated by " ",

                : sm_name separated by " "

    from dictionary.columns

    where libname = "SASHELP" & memname = "CLASS" & name not in ("Name", "Sex");

quit;

data temp;

set sashelp.class ;

keep &all_name. &sm_name. name ;

array  avar {*} &all_name. ;

array  svar {*} &sm_name. ;

do i = 1 to dim(avar);

    svar(i) = avar(i);

end;

run;

Good luck!

Anca.

Occasional Contributor
Posts: 14

Re: Macro to contain list of variable names

Hey anca,

Anca, romanian girl name i'm guessing :smileygrin:, nice !

Thank you for your feedback.

I tried the given code with some modifications. to add 3 more extra tables. I need to use them to keep the univariate analysis results. It gave me the name as requested.

I will carry and try on applying it to the rest needed to see if it fits in the whole process right.

Super Contributor
Posts: 543

Re: Macro to contain list of variable names

Smiley Wink

Occasional Contributor
Posts: 14

Re: Macro to contain list of variable names

Thank you very much, seems to work.

I'll be back if i have any other requests :smileysilly:

Gd day to you Smiley Wink

Super Contributor
Posts: 543

Re: Macro to contain list of variable names

Glad it worked.

Smiley Happy

☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 400 views
  • 0 likes
  • 2 in conversation