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.
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).
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 !
yes i know it should be perfectly fine right, but here i tried it again but still no rows were updated
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.
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 wrote:
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.