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;
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
;;;;
sorry for the typo in the message heading (data instead of date)
They look like delimiters, why not treat them as such?
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,
comma can be used as delimiter, but there is only one semicolon (;), how could we deal with it ??
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
;;;;
Tom,
I have to clean this data and put it back as csv file. The first one works alright for me. Thanks,
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.