BookmarkSubscribeRSS Feed
Dhana18
Obsidian | Level 7

Good morning,

I wanted to modify the value (from blank to 1) in one of the records. This is how i coded. Visdate is a character variable.

DATA SUBMTWO.Clinicdata29_1;
SET SUBMTWO.Clinicdata29;
IF CL_PATIENTID='50055' and visdate="11/27/2017" THEN TOC_VIS='1';
RUN;
proc print data=SUBMTWO.Clinicdata29_1;
var cl_patientid toc_viss;
where cl_patientid="50055";
run;

 

Log shows no erreor.

DATA SUBMTWO.Clinicdata29_1;
130 SET SUBMTWO.Clinicdata29;
131 IF CL_PATIENTID='50055' and visdate="11/27/2017" THEN TOC_VISs='1';
132 RUN;

NOTE: There were 3414 observations read from the data set SUBMTWO.CLINICDATA29.
NOTE: The data set SUBMTWO.CLINICDATA29_1 has 3414 observations and 58 variables.
NOTE: DATA statement used (Total process time):
real time 0.18 seconds
cpu time 0.03 seconds

 

What am i doing it wrong?

 

 

 

 

21 REPLIES 21
Reeza
Super User

Test your conditions individually and see which is not catching the record. 

 

 

 

DATA SUBMTWO.Clinicdata29_1;
SET SUBMTWO.Clinicdata29;
IF CL_PATIENTID='50055' then flag1=1;
if visdate="11/27/2017" flag2=1;
RUN;

You should also show the output you did get from the PROC PRINT.

 


@Dhana18 wrote:

Good morning,

I wanted to modify the value (from blank to 1) in one of the records. This is how i coded. Visdate is a character variable.

DATA SUBMTWO.Clinicdata29_1;
SET SUBMTWO.Clinicdata29;
IF CL_PATIENTID='50055' and visdate="11/27/2017" THEN TOC_VIS='1';
RUN;
proc print data=SUBMTWO.Clinicdata29_1;
var cl_patientid toc_viss;
where cl_patientid="50055";
run;

 

Log shows no erreor.

DATA SUBMTWO.Clinicdata29_1;
130 SET SUBMTWO.Clinicdata29;
131 IF CL_PATIENTID='50055' and visdate="11/27/2017" THEN TOC_VISs='1';
132 RUN;

NOTE: There were 3414 observations read from the data set SUBMTWO.CLINICDATA29.
NOTE: The data set SUBMTWO.CLINICDATA29_1 has 3414 observations and 58 variables.
NOTE: DATA statement used (Total process time):
real time 0.18 seconds
cpu time 0.03 seconds

 

What am i doing it wrong?

 

 

 

 


 

Dhana18
Obsidian | Level 7

Reeza,

I ggot this error message and

137 DATA SUBMTWO.Clinicdata29_1;

138 IF CL_PATIENTID='50055' then flag1=1;

139 if visdate="11/27/2017" flag2=1;

-----

22

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, ;, <, <=,

<>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=,

|, ||, ~=.

 

Then I di d this

DATA SUBMTWO.Clinicdata29_1;

IF CL_PATIENTID='50055' then flag1 = "1";

if visdate="11/27/2017" then flag2 = "1";

RUN;

 

149 DATA SUBMTWO.Clinicdata29_1;

150 IF CL_PATIENTID='50055' then flag1 = "1";

151 if visdate="11/27/2017" then flag2 = "1";

152 RUN;

NOTE: Variable CL_PATIENTID is uninitialized.

NOTE: Variable visdate is uninitialized.

NOTE: The data set SUBMTWO.CLINICDATA29_1 has 1 observations and 4 variables.

NOTE: DATA statement used (Total process time):

real time 0.11 seconds

cpu time 0.06 seconds

 

CL_Patientid can be repeated, because same patient may have come to the clinic multiple times in a year. That is why I used visdate.

Reeza
Super User
It's missing the THEN, add it to the second IF condition. And paste your whole log, including from the PROC PRINT, BallardW is likely correct in his answer.
Dhana18
Obsidian | Level 7
here is the output
The SAS System


Obs flag1 flag2 CL_PATIENTID TOC_VIS
839 1 . 50055
1085 1 . 50055
1203 1 . 50055
same patient visited the clinic multiple times and I only want to have 1 on a specific visdate. Please help.
Reeza
Super User

You'll notice that flag2 is never set. 

 

 

Show a proc contents on your main data set, how you're specifying the date appears to be part of the issue. 

And you've never shown your log including the PROC PRINT step. Include both of these in your next response please. 


@Dhana18 wrote:
here is the output
The SAS System


Obs flag1 flag2 CL_PATIENTID TOC_VIS
839 1 . 50055
1085 1 . 50055
1203 1 . 50055
same patient visited the clinic multiple times and I only want to have 1 on a specific visdate. Please help.

 

Dhana18
Obsidian | Level 7

Reeza,

Here is the log.

DATA SUBMTWO.Clinicdata29_1;

272 SET SUBMTWO.Clinicdata29;

273

274 IF CL_PATIENTID='50055' then flag1=1;

275 if visdate="11/27/2017" then flag2=1;

276 RUN;

NOTE: There were 3414 observations read from the data set SUBMTWO.CLINICDATA29.

NOTE: The data set SUBMTWO.CLINICDATA29_1 has 3414 observations and 59 variables.

NOTE: DATA statement used (Total process time):

real time 0.11 seconds

cpu time 0.03 seconds

 

proc print data=SUBMTWO.Clinicdata29_1;

var flag1 flag2 cl_patientid TOC_VIS;

where cl_patientid="50055";

run;

 

here is the result

Obs flag1 flag2 CL_PATIENTID TOC_VIS83910851203

1.50055 
1.50055 
1.50055

 

I DONOT want to flag on all visit just one specific date.

Dhana18
Obsidian | Level 7

Reeza,

Proc contents here. I removed the other variables.

Alphabetic List of Variables and Attributes
#VariableTypeLenFormatInformatLabel
1CL_PATIENTIDChar7$7.00$7.00CL_PATIENTID
57TOC_VISChar1$1.00$1.00TOC_VIS
4VISDATEChar10$10.00$10.00VISDATE
novinosrin
Tourmaline | Level 20
Modifying variable value
 

You wanted to modify the value (from blank to 1) in one of the records. This is how i coded. Visdate is a character variable.

 

Log shows no erreor.

 

I am unable to understand your question

 

 

EDITed:

 

Assumption 

 

some leading/trailing banks?

 

If yes use strip

 

IF Strip(CL_PATIENTID)='50055' and strip(visdate)="11/27/2017" THEN TOC_VIS='1';

 

Dhana18
Obsidian | Level 7
165 DATA SUBMTWO.Clinicdata29_1;
166 SET SUBMTWO.Clinicdata29;
167 IF Strip(CL_PATIENTID)='50055' and strip(visdate)="11/27/2017" THEN TOC_VIS='1';
168 RUN;

NOTE: There were 3414 observations read from the data set SUBMTWO.CLINICDATA29.
NOTE: The data set SUBMTWO.CLINICDATA29_1 has 3414 observations and 57 variables.
NOTE: DATA statement used (Total process time):
real time 0.07 seconds
cpu time 0.01 seconds
Did not work 😞
ballardw
Super User

@Dhana18 wrote:

Good morning,

I wanted to modify the value (from blank to 1) in one of the records. This is how i coded. Visdate is a character variable.

DATA SUBMTWO.Clinicdata29_1;
SET SUBMTWO.Clinicdata29;
IF CL_PATIENTID='50055' and visdate="11/27/2017" THEN TOC_VIS='1';
RUN;
proc print data=SUBMTWO.Clinicdata29_1;
var cl_patientid toc_viss;
where cl_patientid="50055";
run;

 

Log shows no erreor.

DATA SUBMTWO.Clinicdata29_1;
130 SET SUBMTWO.Clinicdata29;
131 IF CL_PATIENTID='50055' and visdate="11/27/2017" THEN TOC_VISs='1';
132 RUN;

NOTE: There were 3414 observations read from the data set SUBMTWO.CLINICDATA29.
NOTE: The data set SUBMTWO.CLINICDATA29_1 has 3414 observations and 58 variables.
NOTE: DATA statement used (Total process time):
real time 0.18 seconds
cpu time 0.03 seconds

 

What am i doing it wrong?


Check your data set. I bet you have now have a variable named toc_viss that only has one value of '1' and blank for the rest. This would likely be the rightmost column if you use the table viewer or the last column in a proc print output.

Dhana18
Obsidian | Level 7

Thank you al for trying to help me. I tried all of the suggested codes,  but so far it is not working.

ballardw
Super User

@Dhana18 wrote:

Thank you al for trying to help me. I tried all of the suggested codes,  but so far it is not working.


Please post Code or log entries by copy from the editor or log and paste into a code box opened using the {I}. That will preserve code and error message formatting.

Example:

2297  data work.junk;
2298     set sashelp.class;
2299     if sex='F' flag=1;
                    ----
                    22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, ;, <, <=,
              <>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=,
              |, ||, ~=.

2300  run;

Now we can see the underscore characters under the word FLAG and that gives us the hint that the 'THEN' is missing when you want to assign the value.

 

Also when you pasted this bit:

149 DATA SUBMTWO.Clinicdata29_1;
150 IF CL_PATIENTID='50055' then flag1 = "1";
151 if visdate="11/27/2017" then flag2 = "1";
152 RUN;

NOTE: Variable CL_PATIENTID is uninitialized.
NOTE: Variable visdate is uninitialized.
NOTE: The data set SUBMTWO.CLINICDATA29_1 has 1 observations and 4 variables

There is no set statement. So there is nothing read. Your output for this data would have 1 record and 4 variables because there was not instruction to create more records and you only use the names of 4 variables.

 

When you show this output:

proc print data=SUBMTWO.Clinicdata29_1;
var flag1 flag2 cl_patientid TOC_VIS;
where cl_patientid="50055";
run;

Obs flag1 flag2 CL_PATIENTID TOC_VIS83910851203

1 . 50055   
1 . 50055   
1 . 50055 

 I DONOT want to flag on all visit just one specific date.

The Proc Print output shows that all of your TOC_VIS values are blank for the records where CL_Patientid is 50055.

Perhaps you need to Print VISDATE instead of TOC_VIS to check your data. That is the variable you are supposedly using to set the Flag2 variable.

Dhana18
Obsidian | Level 7

I used this datastep

DATA SUBMTWO.Clinicdata29_1;

SET SUBMTWO.Clinicdata29;

IF CL_PATIENTID='50055' then flag1=1;

if visdate='11/27/2017' then flag2=1;

RUN;

then used this proc print statement, and this is the output

 

Obs VISDATE CL_PATIENTID83910851203
2017/10/1750055
2017/11/2750055
2017/12/1150055

 

 

novinosrin
Tourmaline | Level 20

try this and let us know the results

 

DATA check;

SET SUBMTWO.Clinicdata29;

IF CL_PATIENTID='50055' or  visdate='11/27/2017' then output;

RUN;

 

Lets do some tests

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 21 replies
  • 940 views
  • 5 likes
  • 4 in conversation