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

folks, could you please tell me which function to use to correct the name sothat either I get rid of ; and , 

or replace ; with , and use translate function in my output .csv file? 

   I am unable to read the data to begin with. 

         thanks in advance.  

 


data check;
input name $150.;
name_correct=compress(name,'','');
cards;
daniel - height 72 inches, weight 250 pounds;race african american
jack - height 60 inches, weight 150 pounds,race Caucasian
Lee - height 75 inches, weight 175 pounds,race mixed
;
run;
data _null_;
set check;
file "path.csv";
put 'demographics';
put 'name';
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

What are you trying to do? Are you trying to read that data into a dataset?  If so what do you want the result to look like?

It looks more like you are reading it in and then writing it back out again to another text file.  Why?

Perhaps you want to re-write it with the semi-colons replaced by commas?

data check;
  infile cards truncover ;
  input line $char150.; 
  line = translate(line,',',';');
  file 'path.csv' ;
  len = lengthn(line);
  put line $varying150. len ;
cards4;
daniel - height 72 inches, weight 250 pounds;race african american
jack - height 60 inches, weight 150 pounds,race Caucasian
Lee - height 75 inches, weight 175 pounds,race mixed
;;;;

 Perhaps you can just read it as it is?

data check;
  length name height weight race $100 ;
  infile cards dsd dlm='-,;' truncover ;
  input name height weight race ;
  if lowcase(height)=:'height' then height=left(substr(height,7));
  if lowcase(weight)=:'weight' then weight=left(substr(weight,7));
  if lowcase(race)=:'race' then race=left(substr(race,5));
cards4;
daniel - height 72 inches, weight 250 pounds;race african american
jack - height 60 inches, weight 150 pounds,race Caucasian
Lee - height 75 inches, weight 175 pounds,race mixed
;;;;

image.png

View solution in original post

6 REPLIES 6
buddha_d
Pyrite | Level 9

sorry for the typo in the message heading (data instead of date)

Reeza
Super User

They look like delimiters, why not treat them as such?

buddha_d
Pyrite | Level 9

Reeza,

            I want to get it out as it is or with commas or space delimiters, but as a single row. so we will have 3 rows in output. Getting semicolon out of my way is the big problem and I can't find solution. 

thanks,

buddha_d
Pyrite | Level 9

comma can be used as delimiter, but there is only one semicolon (;), how could we deal with it ??

Tom
Super User Tom
Super User

What are you trying to do? Are you trying to read that data into a dataset?  If so what do you want the result to look like?

It looks more like you are reading it in and then writing it back out again to another text file.  Why?

Perhaps you want to re-write it with the semi-colons replaced by commas?

data check;
  infile cards truncover ;
  input line $char150.; 
  line = translate(line,',',';');
  file 'path.csv' ;
  len = lengthn(line);
  put line $varying150. len ;
cards4;
daniel - height 72 inches, weight 250 pounds;race african american
jack - height 60 inches, weight 150 pounds,race Caucasian
Lee - height 75 inches, weight 175 pounds,race mixed
;;;;

 Perhaps you can just read it as it is?

data check;
  length name height weight race $100 ;
  infile cards dsd dlm='-,;' truncover ;
  input name height weight race ;
  if lowcase(height)=:'height' then height=left(substr(height,7));
  if lowcase(weight)=:'weight' then weight=left(substr(weight,7));
  if lowcase(race)=:'race' then race=left(substr(race,5));
cards4;
daniel - height 72 inches, weight 250 pounds;race african american
jack - height 60 inches, weight 150 pounds,race Caucasian
Lee - height 75 inches, weight 175 pounds,race mixed
;;;;

image.png

buddha_d
Pyrite | Level 9

Tom,

         I have to clean this data and put it back as csv file. The first one works alright for me. Thanks,

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1488 views
  • 0 likes
  • 3 in conversation