BookmarkSubscribeRSS Feed
venunaidu
Fluorite | Level 6

in my data I am verify format like 

 

data ds;

infile datalines;

input  Protcol_ID/NO$ 14. Site ID Subject Id;

datalines ;

ONC_AP/01234-1 102.      aaa

ONC_AP/01234-7  103.     abc

ON1_AP/01234-2.  105.     bbc

O1C_AP/01234-2.   108.    ccd

;

run;

in my data cam verify 

1 .length above 15 char 

2.protocal id must  be 15 charcter  charcter 

3.first starting  3 letters must be charcter only

4.first 3 letters a numerical values its an error

5.first 3 letters a combination alphabets and numeric values it's an error

 

how too verify right protocol format , how test length position values specification ,

any can please help how test the protocol using if conditions 

 

 

 
 
 
 
 
first 3 letters no special charcter and spaces its an error 

 

8 REPLIES 8
PaigeMiller
Diamond | Level 26

Maybe I'm not understanding your request ... however ...

 

  1. Length of what?
  2. since the variable is read in as $14. it is never 15 characters
  3. and 4. and 5. use the NOTALPHA function like this:

 

if notalpha(protocol_id)<=3 then error=1;

  

--
Paige Miller
venunaidu
Fluorite | Level 6
Read only correct format of protocol_id .

eg: cds_ap/01234-3 this the correct format of protocol
a1s_ap/01234-3 this the wrong format of protocol
123_ap/01234-3 this the wrong format protocol

length is same in every observation , but format is incorrect , protocol
format is wrong kept into another dataset . how verify the format wrong or
correct .

PaigeMiller
Diamond | Level 26

@venunaidu wrote:

cds_ap/01234-3 this the correct format of protocol
a1s_ap/01234-3 this the wrong format of protocol
123_ap/01234-3 this the wrong format protocol

length is same in every observation , but format is incorrect , protocol
format is wrong kept into another dataset . how verify the format wrong or
correct .

Please explain further ... which format is incorrect and why is it incorrect and what would be correct????? Did you try using the NOTALPHA function as I suggested?

--
Paige Miller
venunaidu
Fluorite | Level 6

 I want find the correct protocol format my protocol format is first letters 3 alphabets,4th position is underscore, 5th to 6th position is alphabets,7th position backward slash , after 7th to 12th position value values after 13th position '-' , 14th to 15th position value. eg (apc_ec/01234-43), how to verify each value in protocol variable , anyone can please me .

PaigeMiller
Diamond | Level 26

@venunaidu wrote:

 I want find the correct protocol format my protocol format is first letters 3 alphabets,4th position is underscore, 5th to 6th position is alphabets,7th position backward slash , after 7th to 12th position value values after 13th position '-' , 14th to 15th position value. eg (apc_ec/01234-43), how to verify each value in protocol variable , anyone can please me .


The part in red is new information that was not stated previously. In the future, you will get faster and better answers if you provide a complete explanation in your first post. 

 

data want;
     set have;
    if notalpha(protocol_id)<=3 or substr(protocol_id,4,1)^='_' or
        0<notalpha(protocol_id,5)<=6 or substr(protocol_id,7,1)^='/'
        or substr(protocol_id,13,1)^='-' or 0<notdigit(protocol_id,8)<=12
        or 0<notdigit(protocol_id,14)<=15 then error=1;
    else error=0;    
run;

 

Please fix your original code to spell variable names correctly, to read the protocol_id so it is 15 characters, and your description talks about backslash but the code above uses a forward slash, which is what your data contains.

--
Paige Miller
ballardw
Super User

@venunaidu wrote:

in my data I am verify format like 

 

data ds;

infile datalines;

input  Protcol_ID/NO$ 14. Site ID Subject Id;

datalines ;

ONC_AP/01234-1 102.      aaa

ONC_AP/01234-7  103.     abc

ON1_AP/01234-2.  105.     bbc

O1C_AP/01234-2.   108.    ccd

;

run;

in my data cam verify 

1 .length above 15 char 

2.protocal id must  be 15 charcter  charcter 

3.first starting  3 letters must be charcter only

4.first 3 letters a numerical values its an error

5.first 3 letters a combination alphabets and numeric values it's an error

 

how too verify right protocol format , how test length position values specification ,

any can please help how test the protocol using if conditions 

 

 

 
 
 
 
 
first 3 letters no special charcter and spaces its an error 

 


First thing, your data step throws errors because of the variable name Protcol_ID/NO is not valid.

Second, your requirement 2 can never be true with that data step as you have forced it to be 14 characters.

 

Is "1 .length above 15 char " supposed to be something like " length greater than 15 characters is an error"? If so, what do you want to happen when it occurs?

 

What do you want to see for output when one of the rules is not met or is an error?

 

If length protocol_id  ne 15 then <do what you want when the length is incorrect>;
venunaidu
Fluorite | Level 6
 
andreas_lds
Jade | Level 19

Please don't double post questions.

Your data step still has errors. Please verify your code.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 8 replies
  • 1073 views
  • 0 likes
  • 4 in conversation