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

Hi all,

I trying to create a data set using datalines with a comma delimiter.  

Here is a snip of my code:


data tv_;
format visitnum visitdy best12.;
length visit $100 tvstrl tvenrl $200;
infile datalines delimiter=',';

input VISITNUM VISIT $ VISITDY TVSTRL $ TVENRL $ ;
datalines;

-21,Screening,-1,INFORMED CONSENT SIGNED,COMPLETION OF SCREENING ASSESSMENTS
101,Cycle 1 Day 1,1,Beginning of Cycle 1 Day 1 Assessments,Completion of Cycle 1 Day 1 Assessments
108,Cycle 1 Day 8,8,Beginning of Cycle 1 Day 8 Assessments,Completion of Cycle 1 Day 8 Assessments
115,Cycle 1 Day 15,15,Beginning of Cycle 1 Day 15 Assessments,Completion of Cycle 1 Day 15 Assessments
201,Cycle 2 Day 1,29,Beginning of Cycle 2 Day 1 Assessments,Completion of Cycle 2 Day 1 Assessments

 

However, this first line is reading in werid and I'm not sure why.

Log errors I'm getting are:


NOTE: Invalid data for VISITDY in line 2968 5-13.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
2968 -21,Screening,-1,INFORMED CONSENT SIGNED,COMPLETION OF SCREENING ASSESSMENTS
VISITNUM= VISITDY= VISIT=-21 TVSTRL=-1 TVENRL=INFORMED CONSENT SIGNED _ERROR_=1 _N_=1
NOTE: Invalid data for VISITDY in line 3032 40-90.
NOTE: LOST CARD.

 

I've attached image of what the dataset created look like 🙂  Help appreciated!!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20


data tv_;
format visitnum visitdy best12.;
length visit $100 tvstrl tvenrl $200;
infile datalines delimiter=',';
input VISITNUM VISIT $ VISITDY TVSTRL $ TVENRL $ ;
datalines;
-21,Screening,-1,INFORMED CONSENT SIGNED,COMPLETION OF SCREENING ASSESSMENTS
101,Cycle 1 Day 1,1,Beginning of Cycle 1 Day 1 Assessments,Completion of Cycle 1 Day 1 Assessments
108,Cycle 1 Day 8,8,Beginning of Cycle 1 Day 8 Assessments,Completion of Cycle 1 Day 8 Assessments
115,Cycle 1 Day 15,15,Beginning of Cycle 1 Day 15 Assessments,Completion of Cycle 1 Day 15 Assessments
201,Cycle 2 Day 1,29,Beginning of Cycle 2 Day 1 Assessments,Completion of Cycle 2 Day 1 Assessments
;

211 data tv_;
6212 format visitnum visitdy best12.;
6213 length visit $100 tvstrl tvenrl $200;
6214 infile datalines delimiter=',';
6215 input VISITNUM VISIT $ VISITDY TVSTRL $ TVENRL $ ;
6216 datalines;

NOTE: The data set WORK.TV_ has 5 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20


data tv_;
format visitnum visitdy best12.;
length visit $100 tvstrl tvenrl $200;
infile datalines delimiter=',';
input VISITNUM VISIT $ VISITDY TVSTRL $ TVENRL $ ;
datalines;
-21,Screening,-1,INFORMED CONSENT SIGNED,COMPLETION OF SCREENING ASSESSMENTS
101,Cycle 1 Day 1,1,Beginning of Cycle 1 Day 1 Assessments,Completion of Cycle 1 Day 1 Assessments
108,Cycle 1 Day 8,8,Beginning of Cycle 1 Day 8 Assessments,Completion of Cycle 1 Day 8 Assessments
115,Cycle 1 Day 15,15,Beginning of Cycle 1 Day 15 Assessments,Completion of Cycle 1 Day 15 Assessments
201,Cycle 2 Day 1,29,Beginning of Cycle 2 Day 1 Assessments,Completion of Cycle 2 Day 1 Assessments
;

211 data tv_;
6212 format visitnum visitdy best12.;
6213 length visit $100 tvstrl tvenrl $200;
6214 infile datalines delimiter=',';
6215 input VISITNUM VISIT $ VISITDY TVSTRL $ TVENRL $ ;
6216 datalines;

NOTE: The data set WORK.TV_ has 5 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

jenim514
Pyrite | Level 9

Hi @novinosrin .  Did you change anything? You are not getting error?

novinosrin
Tourmaline | Level 20

If you copy/paste the code you wrote , you notice a blank dataline at the start

like


data tv_;
format visitnum visitdy best12.;
length visit $100 tvstrl tvenrl $200;
infile datalines delimiter=',';

input VISITNUM VISIT $ VISITDY TVSTRL $ TVENRL $ ;
datalines;

-21,Screening,-1,INFORMED CONSENT SIGNED,COMPLETION OF SCREENING ASSESSMENTS
101,Cycle 1 Day 1,1,Beginning of Cycle 1 Day 1 Assessments,Completion of Cycle 1 Day 1 Assessments
108,Cycle 1 Day 8,8,Beginning of Cycle 1 Day 8 Assessments,Completion of Cycle 1 Day 8 Assessments
115,Cycle 1 Day 15,15,Beginning of Cycle 1 Day 15 Assessments,Completion of Cycle 1 Day 15 Assessments
201,Cycle 2 Day 1,29,Beginning of Cycle 2 Day 1 Assessments,Completion of Cycle 2 Day 1 Assessments

I removed the blank dataline that is completely unwanted and it worked

jenim514
Pyrite | Level 9

Ohhh, I see.  Thank you!!

 

ballardw
Super User

@jenim514 wrote:

Hi all,

I trying to create a data set using datalines with a comma delimiter.  

Here is a snip of my code:


data tv_;
format visitnum visitdy best12.;
length visit $100 tvstrl tvenrl $200;
infile datalines delimiter=',';

input VISITNUM VISIT $ VISITDY TVSTRL $ TVENRL $ ;
datalines;

-21,Screening,-1,INFORMED CONSENT SIGNED,COMPLETION OF SCREENING ASSESSMENTS
101,Cycle 1 Day 1,1,Beginning of Cycle 1 Day 1 Assessments,Completion of Cycle 1 Day 1 Assessments
108,Cycle 1 Day 8,8,Beginning of Cycle 1 Day 8 Assessments,Completion of Cycle 1 Day 8 Assessments
115,Cycle 1 Day 15,15,Beginning of Cycle 1 Day 15 Assessments,Completion of Cycle 1 Day 15 Assessments
201,Cycle 2 Day 1,29,Beginning of Cycle 2 Day 1 Assessments,Completion of Cycle 2 Day 1 Assessments

 

However, this first line is reading in werid and I'm not sure why.

Log errors I'm getting are:


NOTE: Invalid data for VISITDY in line 2968 5-13.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
2968 -21,Screening,-1,INFORMED CONSENT SIGNED,COMPLETION OF SCREENING ASSESSMENTS
VISITNUM= VISITDY= VISIT=-21 TVSTRL=-1 TVENRL=INFORMED CONSENT SIGNED _ERROR_=1 _N_=1
NOTE: Invalid data for VISITDY in line 3032 40-90.
NOTE: LOST CARD.

 

I've attached image of what the dataset created look like 🙂  Help appreciated!!


Please repost your code in a code box opened using the forum's {I} icon.

 

When I copy the text posted above into my editor I get a blank line between datalines; and your -21 value. So you may have some invalid character in your data that the forum windows removes/ replaces. If there is a blank line in your data then the input is getting confused with the end of line character from the blank line since you didn't provide any of the options to control flow when an end of line is encountered before the complete input statement is read such as MISSOVER, TRUNCOVER and is defaulting to FLOWEVER. So the -21 is  read as the second variable, VISIT, and then encounters "Screening" as the third variable and since VISITDY is numeric you get invalid data.

 

Remove the blank line. Or add TRUNCOVER to the infile statement, though you'll get an observation with missing values for all records.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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