Get the variable names from the table and assign to macro variable var1- varn. Need to get the number of variables first to a macro varialbe &num_vars.
proc sql; select distinct(name) into :var1-:var%trim(%left(&num_vars)) from dictionary.columns where libname="WORK" and memname= "TABLE1" and type= "num"; quit;
- The result is &var1 is varname1, &var2 is varname2 etc.
- use type = “num” to get the varnames only for numeric variables;
- use type = “char” to get the varnames only for character variables.
Layout of dictionary.columns.
Alphabetic List of Variables and Attributes | ||||
---|---|---|---|---|
# | Variable | Type | Len | Label |
10 | format | Char | 49 | Column Format |
12 | idxusage | Char | 9 | Column Index Type |
11 | informat | Char | 49 | Column Informat |
9 | label | Char | 256 | Column Label |
6 | length | Num | 8 | Column Length |
1 | libname | Char | 8 | Library Name |
2 | memname | Char | 32 | Member Name |
3 | memtype | Char | 8 | Member Type |
4 | name | Char | 32 | Column Name |
15 | notnull | Char | 3 | Not NULL? |
7 | npos | Num | 8 | Column Position |
16 | precision | Num | 8 | Precision |
17 | scale | Num | 8 | Scale |
13 | sortedby | Num | 8 | Order in Key Sequence |
18 | transcode | Char | 3 | Transcoded? |
5 | type | Char | 4 | Column Type |
8 | varnum | Num | 8 | Column Number in Table |
14 | xtype | Char | 12 | Extended Type |