SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
mcook
Quartz | Level 8

I have Table1 in the format

 

Var1   Var2   Var3   Var4   Var5   ... ...   Var103

A          E         I        M        Q                    U

B          F         J                   R                    V

C                     K       O

D          H        L        P         T                    X

 

Where Variables Var3 through Var103 are alpha-numeric in alphabetical order, But their alphabetic prefixes are different. So i cannot reference them as Var3-Var103 to create an array.  

 

I also have Table2

Col1       Col2

Var3          1

Var4          2

Var5          3

....

....

Var103     100

 

Is it possible to switch Var3 to Var103  in Table1 with the 1-100 from Table2, so as to be able to reference them as an array.  

 

Then once I finish manipulating the array as needed, switch back to Var3 to Var103?  

 

Or simpler, is there a way to fill the missing values in Table1 with '.' values, without referencing each variable?  

 

6 REPLIES 6
mcook
Quartz | Level 8
Edit:

The Array would be Var4-Var103
PaigeMiller
Diamond | Level 26

Where Variables Var3 through Var103 are alpha-numeric in alphabetical order, But their alphabetic prefixes are different. So i cannot reference them as Var3-Var103 to create an array.  


Does this mean that the variables are not really named Var3 to Var103, but might be something like pig4, duck5, goose6, gorilla7, giraffe8, ..., monkey103?

 

If so, to create an array, you could use

 

array x pig4--monkey103;

 

--
Paige Miller
ballardw
Super User

I would suggest that changing a variable name may be a tad confusing if you don't use the data set for awhile or share the data with others (especially ).

If you only have a few gaps in your integer sequence you could use something like

 

arrray v   var1-var27 var29-var99 var103;

Most places a variable "list" can be used can accept gaps.

 

If the variables are contiguous (next to each other in the data set or have sequential variable order numbers in Proc Contents output) then the double dash @PaigeMiller suggests is appropriate as well as working for non-common names for all.

 

And if there are no other variables that start with the same name you can use the colon list generator.   var: would a list of all variables whose names start with var.

mcook
Quartz | Level 8
No, they do not have sequential numbers in proc contents. How might i go about achieving that?
ballardw
Super User

@mcook wrote:
No, they do not have sequential numbers in proc contents. How might i go about achieving that?

Show us your proc contents variables list information and indicate which variables you need.

PaigeMiller
Diamond | Level 26

@mcook wrote:
No, they do not have sequential numbers in proc contents. How might i go about achieving that?

As long as the variables are sequential in your SAS data set, the numbers in the variable names are not meaningful. The double-dash variable list works in the case of sequential variables.

--
Paige Miller

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 939 views
  • 0 likes
  • 3 in conversation