BookmarkSubscribeRSS Feed
Emma8
Quartz | Level 8
Hi. I have a text file (delimiter=“~”) with about million observations and 500 variables (variables names are invalid SAS names).
The text file contain open and closed quotes, decimal in string. How can I import? Thank you.
7 REPLIES 7
Kurt_Bremser
Super User

In the data step, use

dlm="~" dsd firstobs=2 truncover

in the INFILE statement.

If there is a pattern to the variable names, use a macro to reduce your code.

Emma8
Quartz | Level 8
Thank you.
Does not help it though
ballardw
Super User

"Does not help" is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the <> to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the <> icon or attached as text to show exactly what you have and that we can test code against.

 

You should as an absolute minimum show the code, or the generated code, you attempted.

 

The options @Kurt_Bremser apply to reading a data set with a data step. If you are attempting to use Proc Import then show us.

smantha
Lapis Lazuli | Level 10

did you try the import wizard by giving it a custom delimiter and see what code it generates. The code BallardW posted should work. Please provide your code and logs as suggested.

Emma8
Quartz | Level 8
It was
Rule:
—-+— etc.
Invalid data for ...
I tried to fix by infile recfm=n

But I it does not fix.
I think data contain open or closed quotes and varying length width.

Thank you!
Emma8
Quartz | Level 8



Tom
Super User Tom
Super User

Is the delimiter a comma or a tilde?  Your posted code is trying to use comma as the delimiter.  If you want to tell PROC IMPORT to use tilde as the delimiter then add this statement to the proc import step.

dlm='~';

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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