BookmarkSubscribeRSS Feed
edasdfasdfasdfa
Quartz | Level 8

So if you have many variables, how can you define them without having to write out each one in the input statement? I know that once you have them defined initially you can use variable lists and there are many other options like using _ALL_ , _NUMERIC_ etc, but how about initially. Do you have to type out 20 different variables?

 

 

2 REPLIES 2
Norman21
Lapis Lazuli | Level 10

You might find this discussion useful:

 

https://communities.sas.com/t5/SAS-Programming/Assigning-Multiple-Variables/td-p/582197

Norman.
SAS 9.4 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

Astounding
PROC Star

SAS doesn't know the variable names you want to use unless you tell it.  But if there is a pattern to the variable names, you can define them on the INPUT statement.  For example:

 

input @21 (q1-q20) (2. 1.);

This defines 20 variables, the odd-numbered variables being read from 2 characters of the input data line, and the even-numbered variables being read from 1 character.  So Q1 comes from columns 21-22, Q2 from column 23, Q3 from columns 24-25 etc.

 

While there are many variations possible on this theme, you would need to spell out some detail.  For a more specific answer we would need to know about what the variable names are, as well as where they appear on the raw data line.  It might help to know whether you have an electronic list of the variable names, and what that list looks like (such as how wide they are and whether they are character or numeric).  If you have this information, there are a variety of ways available to provide that information to a SAS program.  But if you don't have it, there's no way for SAS to know.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 948 views
  • 1 like
  • 3 in conversation