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

I have to write a program that reads the data after datalines; in the code part. As you can see i use a assignment to remove the '',$ and the ** in the provided data. However i have to do the program without an assignment, which is quite troublesome. Any ideas on how to change it, so the program reads the code, but ignores "",$ and the **?

Cheers

data PERSONELL;
input @; 
  if not index(_infile_,'****');
  _infile_ = translate(_infile_,' ','$');
  length ID $ 4;
  length DEPT $ 1;
  input ID $ @1 DEPT $ BIRTHDAY date10. +(-5) YEAR :8. Salary comma8./;
  datalines;
A123  4Mar1989  8,6,00
***************
    A037 23Jun1957  21,450
**************
 M015 19Sep1977$17,500
***********
;
run; 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Peter_C
Rhodochrosite | Level 12
To treat unwanted characters as blanks, put them into the DLM= option on an INFILE statement.

this only fails if you also need the DSD option ( not the case here)
Then your data step needs only
Data got it;
INFILE DATALINES dlm= '$ *' ;
Input id :$4. Birthday : date9. Salary :comma11. @1 dept :$1. ;
Datalines;
....And then your lines


View solution in original post

7 REPLIES 7
andreas_lds
Jade | Level 19

What was wrong with the solution provided in https://communities.sas.com/t5/SAS-Programming/How-to-handle-special-characters-in-data/m-p/512848?

 

Does the line with A037 start with blanks (or tab)?

torvin10
Calcite | Level 5

Blanks. And the solution is good, however im trying to do it without assignment statements, and isn´t the 

_infile_ = translate(_infile_,' ','$');

an assignment? 

Shmuel
Garnet | Level 18

What issues do you have?

 

1) why is '/' at the end of the INPUT statement ?

2) is it not your typo having two commas in first line salary ?

    

A123  4Mar1989  8,6,00

3) Your code is: 

input ID $ @1 DEPT $ ......

did you mean:

input id $1. dept $3. .......

the @1 means to read fromthe 1st position of the row

torvin10
Calcite | Level 5

Sas studio(Mac user) 

And the data is at was given to me, and the / from the INPUT statment had sneaked in, thanks. 

Shmuel
Garnet | Level 18

Try next code:

data PERSONELL;
   infile datalines dlm='$' ; /* assuming the $ is the delimiter between vars */
    input ID $4. @;
    if ID = '****' then do; delete; input; end;
else input +(-1) DEPT $1. BIRTHDAY date10. +(-5) YEAR :8. Salary comma8.; datalines; A123 4Mar1989 8,600 *************** A037 23Jun1957 21,450 ************** M015 19Sep1977$17,500 *********** ; run;
Peter_C
Rhodochrosite | Level 12
To treat unwanted characters as blanks, put them into the DLM= option on an INFILE statement.

this only fails if you also need the DSD option ( not the case here)
Then your data step needs only
Data got it;
INFILE DATALINES dlm= '$ *' ;
Input id :$4. Birthday : date9. Salary :comma11. @1 dept :$1. ;
Datalines;
....And then your lines


sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1686 views
  • 2 likes
  • 5 in conversation