DATA Step, Macro, Functions and more

read raw data separated by Blank and with missing values

Accepted Solution Solved
Reply
Super Contributor
Posts: 312
Accepted Solution

read raw data separated by Blank and with missing values

The following code does not work. How to correct it? Thanks

 

data have ;
infile datalines missover;
input obs 2. var1 $3 var2 $3 var3 $3 ;
datalines;
obs 	var1	    var2	var3
  1                              Yes
  2      Yes
  3                  Yes
  4                  Yes
  5                  Yes
  6                  Yes
  7                  Yes
  8                  Yes
  9                  Yes
 10                  Yes
 11                  Yes
 12                  Yes
 13      Yes
 14      Yes
 15      Yes
 16      Yes
 17                  Yes
 18                  Yes
 19                  Yes
 20                  Yes
 21      Yes
 22                  Yes
 23                  Yes
 24                  Yes
 25                  Yes
 26      Yes
 27                  Yes
 28                  Yes
 29                  Yes
 30                  Yes
 31                  Yes
 32      Yes
 33                  Yes
 34                  Yes
 35                  Yes
 36      Yes
 37                  Yes
 38                  Yes
 39                  Yes
 40                  Yes
 41                  Yes
 42                  Yes
 43                  Yes
 ;
 run;

Accepted Solutions
Solution
‎02-28-2017 10:24 PM
PROC Star
Posts: 7,360

Re: read raw data separated by Blank and with missing values

You'll have to adjust the following based on what your actual data look like but, for your example, the following would work:

 

data have ;
  infile datalines missover;
  input obs 2-3  var1 $ 10-12 var2 $ 22-24 var3 $ 34-36 ;
  datalines;
  1                              Yes
  2      Yes
  3                  Yes
  4                  Yes
  5                  Yes
  6                  Yes
  7                  Yes
  8                  Yes
  9                  Yes
 10                  Yes
 11                  Yes
 12                  Yes
 13      Yes
 14      Yes
 15      Yes
 16      Yes
 17                  Yes
 18                  Yes
 19                  Yes
 20                  Yes
 21      Yes
 22                  Yes
 23                  Yes
 24                  Yes
 25                  Yes
 26      Yes
 27                  Yes
 28                  Yes
 29                  Yes
 30                  Yes
 31                  Yes
 32      Yes
 33                  Yes
 34                  Yes
 35                  Yes
 36      Yes
 37                  Yes
 38                  Yes
 39                  Yes
 40                  Yes
 41                  Yes
 42                  Yes
 43                  Yes
 ;
 run;  

Art, CEO, AnalystFinder.com

View solution in original post


All Replies
Super User
Posts: 6,928

Re: read raw data separated by Blank and with missing values

When you specify the dsd option in the infile statement, successive delimiters are interpreted as a missing value.

But then you need to take care that only the correct number of delimiters appears between values.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 17,784

Re: read raw data separated by Blank and with missing values

In a case like this, you'll need to upload a sample of the exact file. It's important to be able to see exactly how the delimiters are structured. The forum can easily garble this so including the text file is the only way to ensure that you get a solution that actually will work on your data. 


For example, is it by chance fixed width?

 

Super Contributor
Posts: 312

Re: read raw data separated by Blank and with missing values

I actually used proc print to get the three columns. I wanted to ask a question about taking max of the three column and tried to give some example data with datalines, but I had a problem to read them in.
Solution
‎02-28-2017 10:24 PM
PROC Star
Posts: 7,360

Re: read raw data separated by Blank and with missing values

You'll have to adjust the following based on what your actual data look like but, for your example, the following would work:

 

data have ;
  infile datalines missover;
  input obs 2-3  var1 $ 10-12 var2 $ 22-24 var3 $ 34-36 ;
  datalines;
  1                              Yes
  2      Yes
  3                  Yes
  4                  Yes
  5                  Yes
  6                  Yes
  7                  Yes
  8                  Yes
  9                  Yes
 10                  Yes
 11                  Yes
 12                  Yes
 13      Yes
 14      Yes
 15      Yes
 16      Yes
 17                  Yes
 18                  Yes
 19                  Yes
 20                  Yes
 21      Yes
 22                  Yes
 23                  Yes
 24                  Yes
 25                  Yes
 26      Yes
 27                  Yes
 28                  Yes
 29                  Yes
 30                  Yes
 31                  Yes
 32      Yes
 33                  Yes
 34                  Yes
 35                  Yes
 36      Yes
 37                  Yes
 38                  Yes
 39                  Yes
 40                  Yes
 41                  Yes
 42                  Yes
 43                  Yes
 ;
 run;  

Art, CEO, AnalystFinder.com

Super Contributor
Posts: 312

Re: read raw data separated by Blank and with missing values

Thank you, Art, this should work. 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 128 views
  • 0 likes
  • 4 in conversation