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

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

1 ACCEPTED SOLUTION

Accepted Solutions
AG_Stats
Quartz | Level 8

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

7 REPLIES 7
Loko
Barite | Level 11

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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                                   . 

...

Astounding
PROC Star

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)

AG_Stats
Quartz | Level 8

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
Camp
Fluorite | Level 6

Thanks for your solution and video links

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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