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.
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;
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.
Ballardw,
I sent a file.
I would appreciate if you may help me!
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)
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 | . |
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;
Thanks Ballardw!!
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!
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.