12-19-2013 05:22 AM
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..
12-19-2013 05:34 AM
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.
12-19-2013 05:42 AM
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 ??
12-19-2013 07:35 AM
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.
12-19-2013 07:56 AM
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.
12-20-2013 05:17 AM
As you originally mentioned that data is in text file, the following code is working fine for me:
infile "D:\new.txt" dlm = ',;';
input (first last) (2* : $10.) @@;
12-19-2013 09:12 AM
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;
12-19-2013 01:58 PM
filename sugus temp;
put "Sanjeev,Kuridi ;Ramesh ,varma;Rajesh,kumar";
put "zdeb, mike ; clinton, bill;";
put "z, jay;";
infile sugus dlm=',;';
input (last first) (: $20.) @@;
proc print data=new noobs;