Hello:
I found a problem when I try to create SAS dataset. I would like to add "TOF +/- PA, DORV -TGA" into column Analysis. But the result only shows "TOF +/- PA", please advice how to fix it. Thanks.
data test1;
infile datalines dsd;
input Author : $20. Analysis : $100. Product : $100.;
datalines;
Alissa, Cleft Lip +/- Palate, LABETOLOL,
Marilyn, TOF +/- PA, DORV -TGA, BUTALBITAL,
;
Using DSD tells SAS to use commas as a delimiter. Commas mark the end of a variable. You can't have it both ways and expect that commas sometimes are taken to be text. They either mark the end of a variable or they don't.
If you want commas to be text, you can change the commas between fields to something else such as | and replace dsd with dlm='|'
did it in a hurry, but you can organize it better or you would at-least get the idea
data test1;
infile datalines dsd truncover col=d;
input Author : $20. @;
_k=length(strip(scan(_infile_ ,-2,',','M' )));
_fwidth=length(strip(_infile_))-_k-d-1;
input @(d+1) Analysis $varying25. _fwidth product : $100.;
drop _:;
datalines;
Alissa, Cleft Lip +/- Palate, LABETOLOL,
Marilyn, TOF +/- PA, DORV -TGA, BUTALBITAL,
;
Using DSD tells SAS to use commas as a delimiter. Commas mark the end of a variable. You can't have it both ways and expect that commas sometimes are taken to be text. They either mark the end of a variable or they don't.
If you want commas to be text, you can change the commas between fields to something else such as | and replace dsd with dlm='|'
You better define a dofferent delimiter between the variables, such as '#' assuming is not in any variable data:
data test1;
infile datalines dlm='#';
input Author : $20. Analysis : $100. Product : $100.;
datalines;
Alissa # Cleft Lip +/- Palate # LABETOLOL,
Marilyn # TOF +/- PA, DORV -TGA # BUTALBITAL,
;
Thanks, Shmuel. Your codes works too!
Thanks for everyone's quick response. I picked the easiest way.
@ybz12003, i wonder whether changing the raw file structure the most easy or convenient thing to do. I thought you were after how to deal with embedded delimiter ',' in a comma separated file which gives rise to the challenge of using infile options and play with input buffer columns.
Anyway, If you are so comfortable with the former, all you need to do is wrap your values with quotes to make the code you wrote to work
/*so no changes in your code, just the quotes " around values */
data test1;
infile datalines dsd;
input Author : $20. Analysis : $100. Product : $100.;
datalines;
"Alissa", "Cleft Lip +/- Palate", "LABETOLOL",
"Marilyn", "TOF +/- PA, DORV -TGA", "BUTALBITAL",
;
Thank you so much, Novinosrin. That works too!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.