BookmarkSubscribeRSS Feed
randythomas84
Calcite | Level 5

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!!

7 REPLIES 7
Reeza
Super User

@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!!


randythomas84
Calcite | Level 5

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

novinosrin
Tourmaline | Level 20
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;
randythomas84
Calcite | Level 5

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?

novinosrin
Tourmaline | Level 20

@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

randythomas84
Calcite | Level 5

@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.

novinosrin
Tourmaline | Level 20

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1712 views
  • 1 like
  • 3 in conversation