BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.


Suppose the following csv file (named "raw"), with 3 variables (A, B, C):

A  B  C

2  5  6

4  7  5

5  0  2

6  2  4

.  9  3

.  8  5

.  5  9

.  .   7

I want to read this information and save on a data set named "raw_data_readed":

data raw_data_readed;

  infile ' c:\raw.csv ' dlm= ',' ;

  input var1 var2 var3;

run;

But when SAS reads, the result is:

obs   var1 var2 var3

1       2     5     6

2       4     7     5

3       5     0     2

4       6     2     4

Is there a way to have obs 1 to 8?

Although here I told that there are only 3 variables, in real there are more variables.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

The DSD option is what you were looking for. Here is an example reading datalines instead of an external file so folks can see whats going on.

data raw_data_readed;

  infile datalines  dlm= ',' dsd ;

  input var1 var2 var3 var4;

datalines;

2,5,6,2

4,7,5,9

5,0,2,8

6,2,4,5

,9,3,

,8,5,7

,5,9,0

,,7,

run;

View solution in original post

5 REPLIES 5
ballardw
Super User

Your example data is not in CSV format. If the data is actually csv and no informat has been associated with variables I would expect to get missing values for Var1 for obs 5-8 and missing for var2 on obs 8 but not completely missing records.

You may need to post your actual reading code if not a few lines of data.

Wagner_Alvarenga
Calcite | Level 5

Ballardw,

I sent a file.

I would appreciate if you may help me!

Wagner_Alvarenga
Calcite | Level 5

For the file that I sent, how should I do tho have the following variables:

Data Set TEST (with 4 variables var1, var2, var3, var4)

      

2562
4759
5028
6245
.93.
.857
.590
..7.
ballardw
Super User

The DSD option is what you were looking for. Here is an example reading datalines instead of an external file so folks can see whats going on.

data raw_data_readed;

  infile datalines  dlm= ',' dsd ;

  input var1 var2 var3 var4;

datalines;

2,5,6,2

4,7,5,9

5,0,2,8

6,2,4,5

,9,3,

,8,5,7

,5,9,0

,,7,

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 575 views
  • 0 likes
  • 2 in conversation