BookmarkSubscribeRSS Feed
himansu
Calcite | Level 5

Hello,

I want to read the following dataset in SAS. Please help me how to read correctly each column.

Thanks.

var1       var2       var3           var4                    var5

0.2125  5       5       0.00157247      1

0.2125  4       16      0.00395883      1

0.4625  0       2       8.30714e-05     1

0.4625  2       6       0.00180167      1

0.225   3       4       0.00293251      1

0.225   10      4       0.0025647       1

0.4875  6       7       0.00195159      1

0.4875  0       13      0.00211006      1

-1      0       2       0.00162652      1

-1      1       4       0.00071804      1

0.1125  0       2       0.00114967      1

-2      0       2       0.00119367      0

-2      0       3       0.000510575     0

-2      0       2       0.000638305     0

0.25    0       2       0.00571146      0

0.25    0       2       0.00431435      0

7 REPLIES 7
art297
Opal | Level 21
Kurt_Bremser
Super User

If it is already a dataset, you read it by using the set or merge statements (or from ... in proc sql), all variables will be available to the data step or sql.

If you mean how to read external data into a SAS dataset, you need to specify the structure of the file to be read (which is not yet a dataset in SAS diction) and/or sample data in the original format.

himansu
Calcite | Level 5

Hello, the data in an ascii file and I try to read this in SAS using the following command. After the proc print statement, I don't the values in the result window. Only variables names are there and all entries are just filled by dot sign. I couldn't figure out what is wrong (may be something related to formatting of the variables). I just started learning SAS. Any help is appreciated.

data data_in;

infile "/folders/myshortcuts/SAS-Code/test.txt";

input

var1 var2 var3 var4 var5

;

run;

proc print data=data_in;

run;

art297
Opal | Level 21

What feedback was in your log? That will usually give you a good idea of what you did incorrectly.

himansu
Calcite | Level 5

There are few notes in the log file about invalid data. No errors or warning messages. Below is the log message attached.

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

42 ;

43 data data_in;

44 infile "/folders/myshortcuts/SAS-Code/test.txt";

45 input

46 var1 var2 var3 var4 var5

47 ;

48 run;

NOTE: The infile "/folders/myshortcuts/SAS-Code/test.txt" is:

  Filename=/folders/myshortcuts/SAS-Code/test.txt,

  Owner Name=root,Group Name=vboxsf,

  Access Permission=-rwxrwx---,

  Last Modified=01Mar2015:18:26:30,

  File Size (bytes)=121

NOTE: Invalid data for var1 in line 1 1-23.

NOTE: Invalid data for var2 in line 2 1-24.

NOTE: Invalid data for var3 in line 3 1-24.

NOTE: Invalid data for var4 in line 4 1-23.

NOTE: Invalid data for var5 in line 5 1-22.

RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 

5 CHAR 0.225.3.4.0.00293251.1 22

  ZONE 3233303030323333333303

  NUMR 0E225939490E0029325191

NOTE: Invalid data errors for file '"/folders/myshortcuts/SAS-Code/test.txt"' occurred outside the printed range.

NOTE: Increase available buffer lines with the INFILE n= option.

var1=. var2=. var3=. var4=. var5=. _ERROR_=1 _N_=1

NOTE: 5 records were read from the infile "/folders/myshortcuts/SAS-Code/test.txt".

  The minimum record length was 22.

  The maximum record length was 24.

NOTE: SAS went to a new line when INPUT statement reached past the end of a line.

NOTE: The data set WORK.DATA_IN has 1 observations and 5 variables.

NOTE: DATA statement used (Total process time):

  real time 0.07 seconds

  cpu time 0.09 seconds

  

49 

50 proc print data=data_in;

51 run;

NOTE: There were 1 observations read from the data set WORK.DATA_IN.

NOTE: The PROCEDURE PRINT printed page 2.

NOTE: PROCEDURE PRINT used (Total process time):

  real time 0.08 seconds

  cpu time 0.09 seconds

  

52 

53 

54 ;

55 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

65 ;

dkb
Quartz | Level 8 dkb
Quartz | Level 8

You have tab characters in your data but you haven't told SAS that they are there.  Try adding dlm='09'x to your infile statement.

art297
Opal | Level 21

I would guess that dkb is correct and adding dlm='09'x to your infile statement will correct the problem.

Your log showed:

CHAR 0.225.3.4.0.00293251.1 22

ZONE 3233303030323333333303

NUMR 0E225939490E0029325191

The combination of zone and number represent the hexadecimal equivalents of your characters. Reading across the line:

30 represents the char 0

2E represents a decimal point

32 represents the char 2

32 represents the char 2

35 represents the char 5

09 represents a tab character

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3965 views
  • 0 likes
  • 4 in conversation