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

the case is under "relationship" column, there are "Husband" and "Wife". i want to change "Husband" and "Wife" into "Married".

 

PROC SQL;
UPDATE WORK.IMPORT
SET Relationship ='Married'
WHERE Relationship ='Husband';

 

i tried to do it like that, but then there is no rows updated.

please help me

 

Many thanks.

Best regards,

Hazim.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

The you need to very carefully inspect the values that are actually stored in the dataset.

Run

data test;
set import;
rel_hex = put(relationship,$hex30.);
run;

to see if you have any specialties in the strings (leading blanks, undisplayable characters).

View solution in original post

10 REPLIES 10
Kurt_Bremser
Super User

Works for me:

data have;
input Relationship :$20.;
datalines;
Married
Divorced
Unmarried
Husband
;

proc sql;
update have
  set Relationship ='Married'
  where Relationship ='Husband'
;
quit;

proc print data=have noobs;
run;

Result:

Relationship
Married
Divorced
Unmarried
Married

Take care of spelling, Husband <> husband !

HazimHasanB
Calcite | Level 5

yes i know it should be perfectly fine right, but here i tried it again but still no rows were updated

 

Screenshot 2020-10-27 at 7.17.49 PM.png

Kurt_Bremser
Super User

Then it is in your data; please run

proc contents data=work.import;
run;

proc freq data=work.import;
tables relationship;
run;

and post the results here.

The above two steps are essential for Maxim 3: Know Your Data.

Kurt_Bremser
Super User

The you need to very carefully inspect the values that are actually stored in the dataset.

Run

data test;
set import;
rel_hex = put(relationship,$hex30.);
run;

to see if you have any specialties in the strings (leading blanks, undisplayable characters).

HazimHasanB
Calcite | Level 5
Thank you sir, found out there is actually a space behind every value.
ballardw
Super User

@HazimHasanB wrote:

Screenshot 2020-10-27 at 7.34.43 PM.png


One thing you need to be aware of is Proc Freq, and many procedures, with display character values left justified and remove leading spaces. It may be that your "Husband" should be " Husband" or "  Husband" in a comparison.

Example:

data junk;
   Relationship="            Husband";
run;

proc freq data=junk;
   tables relationship;
run;

You might try  adding a variable with the length of the relationship to see if the displayed length matches the expected:

data junk2;
   Relationship="            Husband";
   rlength=length(relationship);
run;

proc freq data=junk2;
   tables relationship*rlength/list ;
run;

If you observe this behavior then you can use either Left or Strip function to remove the leading spaces.

Ksharp
Super User
Or Try start with operator EQT .

proc sql;
update have
set Relationship ='Married'
where Relationship eqt 'Husband'
;
quit;

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
  • 10 replies
  • 934 views
  • 1 like
  • 4 in conversation