BookmarkSubscribeRSS Feed
suztang
Fluorite | Level 6

Transitioning from SAS EG to SAS ViYa and Studio. In SAS EG, I could check a box during import to convert characters in a var name to make them SAS-compatible. The closest I can get to that in Studio is to use option validvarname=v7, except I don't want my variable names truncated. What's the code to replicate what SAS EG is doing with var names?

7 REPLIES 7
SASKiwi
PROC Star

How long are the variable names that are being truncated? It doesn't matter if you are using EG, SAS Studio, SAS 9.4 or Viya, your SAS variable names are limited to 32 characters.. Variable labels don't have this limitation.

suztang
Fluorite | Level 6

Several of them exceed 32 characters (they're questions from a survey form), but in SAS EG, the var name conversion would simply truncate at 32 characters, which is fine. When I do it in SAS Studio, however, the names get replaced with Var999 (where 999 is the number of the variable's field position), and I really hate this because then I have to go back and rename the thing myself.

 

Also, I want the data import to be compatible with the programs I wrote to analyze them in SAS EG. The fields on the form did not change, just my version of SAS.

Nigel_Pain
Lapis Lazuli | Level 10

The EG import wizard doesn't use SAS code to set the variable names, instead it does something locally in the  client process. So there's not a straight translation you can do to Studio. You'd probably have to write some kind of SAS routine which read and parsed the first line (containing the variable names) before using them to generate length, format, informat and input statements in the main import data step. Which is pretty much what the import wizard does. But that does even more, because it also checks the first X (50?) records to work out variable types, lengths, etc. So not straightforward unfortunately! It's probably easier to write your own import data step and specify the variable attributes manually.

suztang
Fluorite | Level 6

Ow. This table goes out to 155 fields. I checked to see if the import was consistent about which fields it converts to Var999, and of course it is NOT consistent! If I close a session, it may change its idea about which variables to convert to Var999 the next time I open it. I can't even tell what length or special character is causing it to  convert like that.

 

Ugh.

ballardw
Super User

One thing to look at is to see if the variables that come in as Varxxx have the exact same text as another column for the first 32 characters and continue past a total of 32. I've seen that with Proc Import for a long time. (and some of it was survey data with stupid exports of the question text as a column header)

 

In some case I was able to address a bit of this by going into the software exporting the survey data to provide a question number or reference instead of the text of the question.

 

 

suztang
Fluorite | Level 6

Yes! Some of the variables do overlap in this way, but not through 32 character places. And that doesn't explain all the fields being selected for the name conversion. This is so weird.

Tom
Super User Tom
Super User

@suztang wrote:

Transitioning from SAS EG to SAS ViYa and Studio. In SAS EG, I could check a box during import to convert characters in a var name to make them SAS-compatible. The closest I can get to that in Studio is to use option validvarname=v7, except I don't want my variable names truncated. What's the code to replicate what SAS EG is doing with var names?


Are you talking about about reading a TEXT file? Such as a CSV file?  Or do you have some other type of file, like an XLSX file?

 

What CODE are you using in EG?  Or did you use some GUI tool in EG?  Note that the GUI tool in EG for importing a TEXT file does analysis of the file on your PC and then uploads a (potentially) modified version of the file and the code to read it.

What CODE are you using in SAS/Studio?  Or did you use some GUI tool to generate the code?

 

Can you run normal SAS code on your VIYA platform?  Perhaps you could use some other tool to GUESS how to convert the file in a dataset.  You could see if you can get this SAS macro to run on VIYA.

https://github.com/sasutils/macros/blob/master/csv2ds.sas

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1575 views
  • 3 likes
  • 5 in conversation