BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
girlieq97
Obsidian | Level 7

Hello, thank you for any and all help. I am trying to run the below code and keep getting the below errors. Any suggestions on what I am doing wrong? 

 

data temp;
set dat.finger;


if missing=1 then do;
segmentation='mine';
rNumb2=ranuni(5678);
if rNumb2< 0.50 then sun=1;
else sun=2;

If control not in (‘C’,’T’) then rNumb=ranuni(1234);
If control=’C’ then control2=’C’;
Else if control=’T’ then control2=’T’;
Else if rNumb<= 0.25 then control2='C';
else control2='T';

end;

run;

 

ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant,
a missing value, iterator, (. 


ERROR 76-322: Syntax error, statement will be ignored.

ERROR 390-185: Expecting an relational or arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

@girlieq97try this code

data temp;
set dat.finger;

if missing=1 then do;
segmentation='mine';
rNumb2=ranuni(5678);
if rNumb2< 0.50 then sun=1;
else sun=2;
If control not in ('C','T') then rNumb=ranuni(1234);
If control='C' then control2='C';
Else if control='T' then control2='T';
Else if rNumb<= 0.25 then control2='C';
else control2='T';

end;
run;

 I think you were using the ` rather than the ' lol, small thing will get you.

`C'  and 'C' mean different things to SAS you mixed up the quoiting.

View solution in original post

12 REPLIES 12
novinosrin
Tourmaline | Level 20
 data temp;
set dat.finger;


if missing=1 then do;
segmentation='mine';
rNumb2=ranuni(5678);
if rNumb2< 0.50 then sun=1;
else sun=2;

If control not in ('C','T') then rNumb=ranuni(1234);
If control='C' then control2='C';
Else if control='T' then control2='T';
Else if rNumb<= 0.25 then control2='C';
else control2='T';

end;

run;
girlieq97
Obsidian | Level 7

thank you - very much

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

@girlieq97try this code

data temp;
set dat.finger;

if missing=1 then do;
segmentation='mine';
rNumb2=ranuni(5678);
if rNumb2< 0.50 then sun=1;
else sun=2;
If control not in ('C','T') then rNumb=ranuni(1234);
If control='C' then control2='C';
Else if control='T' then control2='T';
Else if rNumb<= 0.25 then control2='C';
else control2='T';

end;
run;

 I think you were using the ` rather than the ' lol, small thing will get you.

`C'  and 'C' mean different things to SAS you mixed up the quoiting.

girlieq97
Obsidian | Level 7

thank you VDD for replying - omgosh something so simple! I reran it and now am getting 

 

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      35:47   36:52   37:44   38:23  
NOTE: Variable control is uninitialized.
NOTE: There were 0 observations read from the data set DAT.finger
NOTE: The data set WORK.TEMP has 0 observations and 256 variables.

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

do you have a list of the variables in SAS dataset DAT.finger?

is control in that list?

girlieq97
Obsidian | Level 7

the whole run takes 90 mins - this was the one piece that seemed to be holding me up so I was trying to figure it out in EG. I am going to try and run the whole code in Unix. I will let you know - I don't think control is showing in the dataset because it was erroring out at first. I will post again when run is done. thank you so much!!

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

good luck.

girlieq97
Obsidian | Level 7
no luck 😕 control is missing from the dataset and another variable. It is already 10pm my time so going to call it a night and start fresh in the morning. thank you for your help though at least that is one less thing I have to worry about in the morning 🙂
Kurt_Bremser
Super User

@girlieq97 wrote:

thank you VDD for replying - omgosh something so simple! I reran it and now am getting 

 

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      35:47   36:52   37:44   38:23  
NOTE: Variable control is uninitialized.
NOTE: There were 0 observations read from the data set DAT.finger
NOTE: The data set WORK.TEMP has 0 observations and 256 variables.


Maxim 3: know your data.

Check if the variables that you want to use are there (proc contents, table view)

Maxim 25: clean log, Maxim 31: computers are dumb

After following Maxim 3, use variables correctly; if type conversions are necessary, do them explicitly yourself, so you have control over formats etc. Don't let that be done automatically, automatisms in software might change.

 

Since you do not have a where condition in your code, this also means that dat.finger has no observations. Which means that this step can never have run for 90 minutes, so your overall code has to be much larger, and an empty dataset points to a severe problem further up in the code. Clean out your code step-by-step from the top. Mark steps and use "run selected".

 

Kurt_Bremser
Super User

The bad quotes are most probably an artifact caused by a word processor.

NEVER use a word processor in programming, use text editors like notepad++ or the SAS Enhanced Editor.

 

Word processors may be used in documentation, but as a frontend for programming they are mostly useless.

 

Since I don't have dat.finger, I can't test it, but try

data temp;
set dat.finger;
if missing = 1
then do;
  segmentation = 'mine';
  rNumb2 = ranuni(5678);
  if rNumb2 < 0.50
  then sun = 1;
  else sun = 2;
  if control in ('C','T')
  then control2 = control;
  else do;
    rNumb = ranuni(1234);
    if rNumb <= 0.25
    then control2 = 'C';
    else control2 = 'T';
  end;
end;
run;

and see if you get your desired result. I've tried to straighten out the unwieldy if-then-else tree that's often hard to maintain.

girlieq97
Obsidian | Level 7

Thank you for your help and observations. This was new code that I was adding to an already establish code run. So I was testing it outside of the larger code. You are absolutely right though I copied the code from a word document and I should have typed it out myself and I was not familiar with the data. I have gotten it to run correctly with the desired results since last night and am good to go this morning. 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

Smiley Happy Great, it is nice to hear that you have that road-block removed from your path.  Smiley Happy

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 12 replies
  • 2465 views
  • 4 likes
  • 4 in conversation