BookmarkSubscribeRSS Feed
venkatnaveen
Obsidian | Level 7

Thanks  data_null.

For the reply to the post.

I am unable to view my post Its telling unauthorised access.

Might be technical bug.

Can u just clarify the steps


infile cards col=c;
   input id :$3. @;
   call scan(_infile_,-2,s,l,' ');
   l=s-c-1;
  
input name $varying64. l dob:mmddyy12. money :comma12.;
  
format dob mmddyy10. money dollar12.;
  
drop s l;

How to import delimited space text file

created by data_null_; in Data Management - View the full discussion

data pita;
   infile cards col=c;
   input id :$3. @;
   call scan(_infile_,-2,s,l,' ');
   l=s-c-1;
  
input name $varying64. l dob:mmddyy12. money :comma12.;
  
format dob mmddyy10. money dollar12.;
  
drop s l;
   list;
  
cards;
001 Christopher Mullensc 11/12/1955 $45,200
002 Michelle Kwo 9/12/1955 $78,123
003 Roger W. McDonald 1/1/1960 $107,200
;;;;
   run;
proc print;
  
run;

2 REPLIES 2
data_null__
Jade | Level 19

Since your name field is not followed by 2 or more delimiters (spaces) you cannot use the & format modifier to read the field with embedded delimiters you will need another way to figure out the location of the end of the name field.  We know that there are two fields to the right of the NAME field and we will use that information (the starting column of the date field)  to find the end of the name field.

data pita;
   infile cards col=c; *COLUMN option variable C is location of column pointer;
  
input id :$3. @; *Read the first field, C will be 4;
  
call scan(_infile_,-2,s,l,' '); *Find the S(tart) column of the 2nd word from the right;
   l=s-c-
1; *Calculate the length of name field for $VARYING informat;
  
*We have all the info now to read the rest of the fields.;
  
input name $varying64. l dob:mmddyy12. money :comma12.;
  
*Good to read SAS documentation concerning each of the statements, options, function, and informats for complete details and examples;
  
format dob mmddyy10. money dollar12.;
  
drop s l;
   list;
  
cards;
001 Christopher Mullensc 11/12/1955 $45,200
002 Michelle Kwo 9/12/1955 $78,123
003 Roger W. McDonald 1/1/1960 $107,200
;;;;
   run;
proc print;
  
run;
venkatnaveen
Obsidian | Level 7

Thanks a lot.

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 893 views
  • 0 likes
  • 2 in conversation