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

I have program like this 

DATA TEST;
SET TEST;
REGID1=(REGNUM)="BLR");
RUN;

I not able to understand this code what is happening here. Need quick help. 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@veeresh10 wrote:

I have program like this 

DATA TEST;
SET TEST;
REGID1=(REGNUM)="BLR");
RUN;

I not able to understand this code what is happening here. Need quick help. 


That particular code shown will do nothing except throw an error about mismatched parentheses.

If the code were like in your question subject line as below:

DATA TEST;
SET TEST;
REGID1=(REGNUM="BLR");
RUN;

Then the intent would likely be that the variable Regid1 to be assigned a numeric value of 1 when the variable Regnum="BLR" and 0 otherwise. I say intent because that might be affected by the presence of the variable Regid1 if it is already in the the data set Test. SAS will return a numeric 1 for any logic comparison that is true and 0 when it is false.

 

Suggestion: When you have questions about how code behaves run the code. If you don't understand then copy from the LOG the data step or procedure code with all notes, warnings and errors. Then on the forum open a text box using the </> icon and paste all the next.

The log would be helpful because it would have shown the error generated by your posted code. If the code runs then there might be messages about 'conversion of numeric to text' which might happen if the varaible Regid1 already exists on the data set test and is a character variable.

 

Warning: Habitual use of code with the same data set on the Data and Set statements like below completely replaces the original Test data set. For new programmers this is likely to result in questions about "why is this value/variable/observartion  here or missing as logic errors but not syntax errors execute. While learning basic code I strongly recommend always creating an different output data set so you can see the differences between the input and output data (Hint: there is a procedure called COMPARE to actually do that task)

data test;
   set test;
/* other code*/
run;

View solution in original post

2 REPLIES 2
ballardw
Super User

@veeresh10 wrote:

I have program like this 

DATA TEST;
SET TEST;
REGID1=(REGNUM)="BLR");
RUN;

I not able to understand this code what is happening here. Need quick help. 


That particular code shown will do nothing except throw an error about mismatched parentheses.

If the code were like in your question subject line as below:

DATA TEST;
SET TEST;
REGID1=(REGNUM="BLR");
RUN;

Then the intent would likely be that the variable Regid1 to be assigned a numeric value of 1 when the variable Regnum="BLR" and 0 otherwise. I say intent because that might be affected by the presence of the variable Regid1 if it is already in the the data set Test. SAS will return a numeric 1 for any logic comparison that is true and 0 when it is false.

 

Suggestion: When you have questions about how code behaves run the code. If you don't understand then copy from the LOG the data step or procedure code with all notes, warnings and errors. Then on the forum open a text box using the </> icon and paste all the next.

The log would be helpful because it would have shown the error generated by your posted code. If the code runs then there might be messages about 'conversion of numeric to text' which might happen if the varaible Regid1 already exists on the data set test and is a character variable.

 

Warning: Habitual use of code with the same data set on the Data and Set statements like below completely replaces the original Test data set. For new programmers this is likely to result in questions about "why is this value/variable/observartion  here or missing as logic errors but not syntax errors execute. While learning basic code I strongly recommend always creating an different output data set so you can see the differences between the input and output data (Hint: there is a procedure called COMPARE to actually do that task)

data test;
   set test;
/* other code*/
run;
Kurt_Bremser
Super User

@veeresh10 wrote:

I have program like this 

DATA TEST;
SET TEST;
REGID1=(REGNUM)="BLR");
RUN;

I not able to understand this code what is happening here. Need quick help. 


As posted, the code will only result in a syntax ERROR (one opening bracket, but two closing brackets).

But if that line is actually

REGID1=(REGNUM="BLR");

then the comparison REGNUM="BLR" is evaluated, and the (boolean) result stored in REGID1.

The code is equivalent to

if regnum = "BLR"
then regid1 = 1;
else regid1 = 0;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 150 views
  • 1 like
  • 3 in conversation