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!
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.
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.
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?
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.
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.