DATA Step, Macro, Functions and more

How to save time while declaring too many variables in VAR statement of a Procedure

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

How to save time while declaring too many variables in VAR statement of a Procedure

Can anyone tell me to how to save time while declaring variables in a var statement.

However, I am familiar with ques1-ques100 etc. but I have different variable names.

 

Please help me.

Thanks


Accepted Solutions
Solution
‎04-28-2016 02:33 AM
Contributor
Posts: 65

Re: How to save time while declaring too many variables in VAR statement of a Procedure

[ Edited ]

Hi, Camp might this image would help you,

 

Untitled1.png

 

Besides this you can use following:

If you want to select all variables then you can leave your var statement (then there should be no class etc. statements in the procedure that you are using where you have to declare some variables)

 

Var1 -numeric- Var2 for all numeric variables between Var1 and var2.

Var1 -char- var2 for all char variables between var1 and var2.

VAR_: all variables that begins with Name VAR (colon with var_ is necessary).

 

Also you can use dataset options like: drop= (to drop some variables) & Keep= (to keep selected variables).

 

Again Besides these you can either use:

1. Drag and Drop of variables from dataset (present in your liabrary) or,

2. You can run query of required dataset and copy the variables that you want (but remember to remove comma(s)).

 

For these two, see the following video:

http://support.sas.com/training/tutorial/studio/index.html

 

See the first video.

Regards,
AG_Stats

View solution in original post


All Replies
Super Contributor
Posts: 308

Re: How to save time while declaring too many variables in VAR statement of a Procedure

It depends on your needs.

 

You can, for example, ignore the var statement in which case sas considers all numeric variables.

proc means data=sashelp.class;
class age;
run;

 

Or you can interrogate the dictionary tables (if you know how to identify the variables) and write the result of the query within a macro variable which you later use in the var statement.

Super User
Super User
Posts: 7,975

Re: How to save time while declaring too many variables in VAR statement of a Procedure

Use a normalised data strucuture, this reduces the amount of "vars" and will make coding far easier:

So instead of:

ID   QUEST1  DOB       AGE VAR1 VAR2 VAR3 IDE OPT ERT...

1     ABCD      21mar12  3     XYZ   DEf    34     5     R    3

 

Something like:
ID   QUESTION    CHARACTER_RESPONSE   NUMERIC_RESPONSE

1     QUEST1        ABCD                                 .

1     DOB              21mar12                            21mar12

1     AGE              3                                       3

2     VAR1             XYZ                                   . 

...

Super User
Posts: 5,513

Re: How to save time while declaring too many variables in VAR statement of a Procedure

The topic you are asking about is usually referred to as "variable lists".  Here are a few more examples that apply to a VAR statement:

 

_numeric_ = all numeric variables

_character_ = all character variables

abc: = all variable names that begin with the characters "abc"

cat -- dog = all variables from cat through dog (in the order that they were created)

cat -numeric- dog = all numeric variables from cat through dog (in the order that they were created)

cat -character- dog = all character variables from cat through dog (in the order that they were created)

Respected Advisor
Posts: 3,799

Re: How to save time while declaring too many variables in VAR statement of a Procedure

Posted in reply to Astounding
Occasional Contributor
Posts: 11

Re: How to save time while declaring too many variables in VAR statement of a Procedure

Posted in reply to Astounding

Thanks

Solution
‎04-28-2016 02:33 AM
Contributor
Posts: 65

Re: How to save time while declaring too many variables in VAR statement of a Procedure

[ Edited ]

Hi, Camp might this image would help you,

 

Untitled1.png

 

Besides this you can use following:

If you want to select all variables then you can leave your var statement (then there should be no class etc. statements in the procedure that you are using where you have to declare some variables)

 

Var1 -numeric- Var2 for all numeric variables between Var1 and var2.

Var1 -char- var2 for all char variables between var1 and var2.

VAR_: all variables that begins with Name VAR (colon with var_ is necessary).

 

Also you can use dataset options like: drop= (to drop some variables) & Keep= (to keep selected variables).

 

Again Besides these you can either use:

1. Drag and Drop of variables from dataset (present in your liabrary) or,

2. You can run query of required dataset and copy the variables that you want (but remember to remove comma(s)).

 

For these two, see the following video:

http://support.sas.com/training/tutorial/studio/index.html

 

See the first video.

Regards,
AG_Stats
Occasional Contributor
Posts: 11

Re: How to save time while declaring too many variables in VAR statement of a Procedure

Thanks for your solution and video links

☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 465 views
  • 8 likes
  • 6 in conversation