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

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,

 

;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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='|'

View solution in original post

7 REPLIES 7
novinosrin
Tourmaline | Level 20
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,
;
Astounding
PROC Star

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='|'

Shmuel
Garnet | Level 18

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,

 

;


 
ybz12003
Rhodochrosite | Level 12

Thanks, Shmuel.   Your codes works too!

ybz12003
Rhodochrosite | Level 12

Thanks for everyone's quick response.   I picked the easiest way. Woman Happy

novinosrin
Tourmaline | Level 20

@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",
;

ybz12003
Rhodochrosite | Level 12

Thank you so much, Novinosrin.   That works too!

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
  • 7 replies
  • 1548 views
  • 3 likes
  • 4 in conversation