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

Hi,

This is a really silly question...

I want to create a data set where one of its column value contains dash in the string. 

here's my code

 

data out;

input id $ description ~$ message ~$ num error ~$;

datalines;

ACN-1-001  "BLABLA" "BLABLA" 4 "BLABLA";

RUN;

 

what i want:

 

id                   description     message      num         error

ACN-1-001    BLABLA          BLABLA         4           BLABLA

 

there's an error message: statement is not valid or it is used out of proper order. I think the id input might need a special format but I don't know which one I should use.

 

 

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

In line data stops on the line BEFORE the line with a semi-colon. So you are not passing any data to the data step.

Remove the semi-colon from the line of data.  Or if the data actually contains semi-colons then use the DATALINES4 (aka CARDS4) statement and use a line with 4 semi-colons to end the data.

data out;
  input id $ description ~$ message ~$ num error ~$;
datalines;
ACN-1-001  "BLABLA" "BLABLA" 4 "BLABLA"
;

Or if the data actually contains semi-colons then use the DATALINES4 (aka CARDS4) statement and use a line with 4 semi-colons to end the data.

data out;
  input id $ description ~$ message ~$ num error ~$;
datalines4;
ACN-1-001  "BLABLA" "BLABLA" 4 "BLABLA"
;;;;

Also if you don't want the quotes as part of the value then don't use the ~ (tilda) modifier on the INPUT statement.

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

In line data stops on the line BEFORE the line with a semi-colon. So you are not passing any data to the data step.

Remove the semi-colon from the line of data.  Or if the data actually contains semi-colons then use the DATALINES4 (aka CARDS4) statement and use a line with 4 semi-colons to end the data.

data out;
  input id $ description ~$ message ~$ num error ~$;
datalines;
ACN-1-001  "BLABLA" "BLABLA" 4 "BLABLA"
;

Or if the data actually contains semi-colons then use the DATALINES4 (aka CARDS4) statement and use a line with 4 semi-colons to end the data.

data out;
  input id $ description ~$ message ~$ num error ~$;
datalines4;
ACN-1-001  "BLABLA" "BLABLA" 4 "BLABLA"
;;;;

Also if you don't want the quotes as part of the value then don't use the ~ (tilda) modifier on the INPUT statement.

laiguanyu001
Fluorite | Level 6

Hi thanks! That solves the problem. I kept the ~$ because I am inputting  sentences for description and message. There are lots of space in each sentence so I thought it'd be a good idea to quote around them? Is this a good idea or do you have other suggestions? 

Tom
Super User Tom
Super User

If the values contain spaces then use a delimiter.

Something like this:

data out;
  infile datalines dsd dlm='|' truncover;
  input id :$20. description :$40. message :$200. num error :$200.;
datalines;
ACN-1-001|BLA BLA|BLA BLA|4|BLA BLA
;

If the value actually contains the delimiter then add quotes around it (  "BLA|BLA" ). The quotes will not become part of the value stored in the variable.

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore 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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 4118 views
  • 1 like
  • 2 in conversation