DATA Step, Macro, Functions and more

Stuck

Reply
New Contributor
Posts: 4

Stuck

I am working on something right now and I am stuck.. can anyone help me??
Data set Errors contains character variables Subj (3 bytes) and PartNumber (8 bytes). create a temporary SAS data set (Check1) with any observations in Errors that violates either of the following two rules: first, Subj should contain only digits, and second PartNumber should contain only the upper case letters L and S and the Digits.

it gives you a set of Datalines which are 
datalines;
001 L1232 Nichole Brown
0a2 L887X Fred Beans
003 12321 Alfred 2 Nice
004 abcde Mary Bumpers
x89 8888S Gill Sandford
;
My Solution isn't working

data a15009.errors;
input subj 
PartsNumber
Name
;
datalines;
001 L1232 Nichole Brown
0a2 L887X Fred Beans
003 12321 Alfred 2 Nice
004 abcde Mary Bumpers
x89 8888S Gill Sandford
;
run;
Proc Print data = a15009.errors;
Run;

Please Help!!

Super User
Posts: 23,295

Re: Stuck

Posted in reply to randythomas84

@randythomas84 wrote:


My Solution isn't working

 

Can you post your non-working solution so we can see what approach you're taking?

 

Spoiler

@randythomas84 wrote:

I am working on something right now and I am stuck.. can anyone help me??
Data set Errors contains character variables Subj (3 bytes) and PartNumber (8 bytes). create a temporary SAS data set (Check1) with any observations in Errors that violates either of the following two rules: first, Subj should contain only digits, and second PartNumber should contain only the upper case letters L and S and the Digits.

it gives you a set of Datalines which are 
datalines;
001 L1232 Nichole Brown
0a2 L887X Fred Beans
003 12321 Alfred 2 Nice
004 abcde Mary Bumpers
x89 8888S Gill Sandford
;
My Solution isn't working

data a15009.errors;
input subj 
PartsNumber
Name
;
datalines;
001 L1232 Nichole Brown
0a2 L887X Fred Beans
003 12321 Alfred 2 Nice
004 abcde Mary Bumpers
x89 8888S Gill Sandford
;
run;
Proc Print data = a15009.errors;
Run;

Please Help!!


New Contributor
Posts: 4

Re: Stuck

Posted in reply to randythomas84

This is my solution it just puts periods in the boxes instead of any names

PROC Star
Posts: 1,582

Re: Stuck

Posted in reply to randythomas84
data  errors;
input subj 
PartsNumber
Name
;
datalines;
001 L1232 Nichole Brown
0a2 L887X Fred Beans
003 12321 Alfred 2 Nice
004 abcde Mary Bumpers
x89 8888S Gill Sandford
;
run;

data correct;
infile cards truncover;
input subj  $
PartsNumber $
Name & $20.
;
datalines;
001 L1232 Nichole Brown
0a2 L887X Fred Beans
003 12321 Alfred 2 Nice
004 abcde Mary Bumpers
x89 8888S Gill Sandford
;
run;
New Contributor
Posts: 4

Re: Stuck

Posted in reply to novinosrin

SAS.JPG

It is still just giving periods instead of giving me the errors and correcting them.

As I read it it should display everything with corrections correct?

PROC Star
Posts: 1,582

Re: Stuck

Posted in reply to randythomas84

@randythomas84  Try applying the conditions listed in the question with an if then statement after the input statement.

 

Please attempt. Trust me you will get the hang of it

for a start if anyalpha(subj)>0 or notdigit(subj)>0 will indicate presence of chars other than digits. My request is for you to try and come back to community to make the discussion more interesting and interactive please

New Contributor
Posts: 4

Re: Stuck

Posted in reply to novinosrin

@novinosrin I would love too only i'm just starting to use SAS and I have no clue what I'm doing still.. I'm sorry I really don't I'm working on it but the syntax is a little weird to me.

PROC Star
Posts: 1,582

Re: Stuck

Posted in reply to randythomas84

meddle with this code and change the conditions as necessary:

 

data errors correct all;
infile cards truncover;
input subj  $
PartsNumber $
Name & $20.;
if anyalpha(subj)>0 or length(compress(partsnumber,'LS','n'))>0 then output errors;
else output correct;
output all;
;
datalines;
001 L1232 Nichole Brown
0a2 L887X Fred Beans
003 12321 Alfred 2 Nice
004 abcde Mary Bumpers
x89 8888S Gill Sandford
;
run;
Ask a Question
Discussion stats
  • 7 replies
  • 131 views
  • 1 like
  • 3 in conversation