BookmarkSubscribeRSS Feed
alexx1
Calcite | Level 5
options validvarname=v7;
proc import datafile='/folders/myfolders/cert/class.txt' dbms=tab out=class replace; delimiter='09'x;
guessingrows=20; run; proc print data=class; run;

When I import tab-delimited file 3 variable , 19 obsevation to sas, only 1 variable, 19 observation is imported. How can I correctly import 3 variable to sas? Thanks! 

This is the log message and results :

 88          ***********************************************************************/
 89             data WORK.CLASS    ;
 90             %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
 91             infile '/folders/myfolders/cert/class.txt' delimiter='09'x MISSOVER DSD lrecl=32767 firstobs=2 ;
 92                informat Name_____Gender___Age $20. ;
 93                format Name_____Gender___Age $20. ;
 94             input
 95                         Name_____Gender___Age  $
 96             ;
 97             if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
 98             run;
 
 NOTE: The infile '/folders/myfolders/cert/class.txt' is:
       Filename=/folders/myfolders/cert/class.txt,
       Owner Name=root,Group Name=vboxsf,
       Access Permission=-rwxrwx---,
       Last Modified=21Dec2020:22:11:58,
       File Size (bytes)=1620
 
 NOTE: 19 records were read from the infile '/folders/myfolders/cert/class.txt'.
       The minimum record length was 80.
       The maximum record length was 80.
 NOTE: The data set WORK.CLASS has 19 observations and 1 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.01 seconds
       cpu time            0.00 seconds
       
 
 19 rows created in WORK.CLASS from /folders/myfolders/cert/class.txt.
   
   
   
 NOTE: WORK.CLASS data set was successfully created.
 NOTE: The data set WORK.CLASS has 19 observations and 1 variables.
 NOTE: PROCEDURE IMPORT used (Total process time):
       real time           0.10 seconds
       cpu time            0.07 seconds
       
 
 99         proc print data=class;
 100        run;
 
 NOTE: There were 19 observations read from the data set WORK.CLASS.
 NOTE: PROCEDURE PRINT used (Total process time):
       real time           0.06 seconds
       cpu time            0.06 seconds
       
 
 101        
 102        OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 114        

output: Here should be 3 variables, but only output  one single variable:

Obs	Name_____Gender___Age

however, 19 obs is printed.

12345678910111213141516171819

Joyce F 11
Thomas M 11
Jane F 12
Louise F 12
James M 12
John M 12
Robert M 12
Alice F 13
Barbara F 13
Jeffery M 13
Carol F 14
Judy F 14
Alfred M 14
Henry M 14
Jenet F 15
Mary F 15
Ronald M 15
William M 15
Philip M 16
2 REPLIES 2
Tom
Super User Tom
Super User

Looks like your file has spaces between the values and not tabs.

There is no need to use PROC IMPORT to read a text file, even if you have a delimited files.  Just write your own data step.  Especially for only three variables.

data class ;
   infile '/folders/myfolders/cert/class.txt' truncover firstobs=2;
   input name :$10. gender :$6. age ;
run;
ballardw
Super User

Look very closely at this stuff

     informat Name_____Gender___Age $20. ;
 93                format Name_____Gender___Age $20. ;
 94             input
 95                         Name_____Gender___Age  $

The string Name_____Gender___Age has NO spaces. So is ONE identifier or only one value was read.

 

When you indicate variables in an input statement there must be at least one space between the names of variables.

Same for FORMAT, Informat, drop, keep and other places where multiple variables are used.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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