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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.