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;
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)?
Blanks. And the solution is good, however im trying to do it without assignment statements, and isn´t the
_infile_ = translate(_infile_,' ','$');
an assignment?
From where do you get such an exercise? I hope it's not out of material that SAS provides for their courses.
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
Sas studio(Mac user)
And the data is at was given to me, and the / from the INPUT statment had sneaked in, thanks.
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;
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.