Dear All,
I am back to to basics.
I am having a list of names in a text file in bellow manner.
"Sanjeev,Kuridi ;Ramesh ,varma;Rajesh,kumar" and so on.
Each name is combination of first name and last with the delimter of " , " and every name is delimited with " ; ".
So i want to create a dataset with a variable name ,in that i have to put all the names.
I am not sure how to deal this kind of data.
I tried to copy all that text and kept under datalines,but getting error because of " ; ".
I wonder if any one have a solutions of this senario..
Thanks,
Sanjeev.K
Check out DATALINES4, this works the same as DATALINES except it allows semi colons in the data. You need to finish the code with 4 semi colons.
Hi Keith,
Thank you for your prompt.
Instead of copying the text from the file and pasting it in datalines ,is there any way to import the data directly ??
Thanks,
Sanjeev.K
Hi
Have a look at the code below. the first DATA Step creates some data according to what you mentioned.
The second DATA Step reads the data from the text file using a semicolon as a delimiter for the firstname, lastname combination. The SCAN function then separates the two names.
Hi,
This works perfectly Bruno,Thanks for your code.
But is there any way to get the data directly with out doing copy paste of data into SAS.
Because if this is one time activity,your code is best suitable,but if it is daily activity,So need to automate this one instead of copying data into SAS everyday.
Any suggestions on this ???
Thanks again for your kind help.
Thanks,
Sanjeev.K
where is the data coming from, a file, a FTP server, a URL, a...?
Hi
As you originally mentioned that data is in text file, the following code is working fine for me:
data this;
infile "D:\new.txt" dlm = ',;';
input (first last) (2* : $10.) @@;
run;
Hi Sanjeev, try this one , it will read the file directly:
data want(keep=first_name last_name);
infile 'infile.txt' truncover;
input line $1000.; /*give here the max length for line*/
do i=1 to countc(line,';')+1;
first_name=scan(scan(line,i,';'),1,',');
last_name=scan(scan(line,i,';'),2,',');
output;
end;
run;
To read directly from an external file use the INFILE statement.
Hi ...
filename sugus temp;
data _null_;
file sugus;
put "Sanjeev,Kuridi ;Ramesh ,varma;Rajesh,kumar";
put "zdeb, mike ; clinton, bill;";
put "z, jay;";
run;
data new;
infile sugus dlm=',;';
input (last first) (: $20.) @@;
run;
proc print data=new noobs;
run;
output ...
last first
Sanjeev Kuridi
Ramesh varma
Rajesh kumar
zdeb mike
clinton bill
z jay
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 16. 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.