i run into this every now and then and i need help with it because i do not get it. i have a cell in a column that has no data apparent in it so it must be null or have a null character or something in it. i need that cell not to be null. i run
data TABLE1; set TABLE1; FIELD1=strip(FIELD2); FIELD2=strip(FIELD2); run;
to clear any data/null characters and remove any spaces in front or behind. so any field should have, if that is working, only nothing or be null, if that is not working, then it will have a null character. so i run to update...
data TABLE1; set TABLE1; if length(FIELD2)<=3 or FIELD2=" " then do; FIELD2=catx('','0000',strip(ID)); end; run;
where ID is just an auto-number field. however it does not update that stupid field. i have also tried in the place of FIELD2, missing(FIELD2), FIELD2=. and i cannot get that field to update to id. but when i run...
proc sql; select FIELD0, FIELD1, FIELD2 from TABLE1 where FIELD2=' '; quit; or proc sql; select FIELD0, FIELD1, FIELD2 from TABLE1 where FIELD2 is NULL; quit;
that field comes up.
can someone help me out with that is going on here and how i can get that to pull in a data step? i dont get it...
sas did not like it...
data TABLE1; set TABLE1; if length(FIELD2)<=3 or call missing(FIELD2) then do; FIELD2=catx('','0000',strip(ID)); end; run;
so that did not work.
it is a character field. i am trying to find null fields and put a value in them. i cannot have null fields. i am just trying to add a few leading zeroes and the output of an autonumbered field as a substitute for no data. every cell needs data at least 4 characters long.
that did not work. that is what i did first. there were 2 null looking fields. that updated one of them however the other is still null (or whatever).
also i tried...
data TABLE1; set TABLE1; call missing(FIELD2); run; data TABLE1; set TABLE1; if length(FIELD2)<=3 or missing(FIELD2) then do; NNBR=catx('','0000',strip(ID)); end; run;
and that set every field to null then filled some with data. ie it did not work.
@me55 wrote:
that did not work. that is what i did first. there were 2 null looking fields. that updated one of them however the other is still null (or whatever).
also i tried...
data TABLE1; set TABLE1; call missing(FIELD2); run; data TABLE1; set TABLE1; if length(FIELD2)<=3 or missing(FIELD2) then do; NNBR=catx('','0000',strip(ID)); end; run;and that set every field to null then filled some with data. ie it did not work.
Hopefully you have a backup of TABLE1 (or a way to recreate it) since both of those steps are overwriting the input dataset.
Your first step is forcing all values of FIELD2 to be missing.
Your second step is assuming that FIELD2 is a character string and testing IF the length of the value of FIELD2 is less than 4 characters. (or missing but the length function will return 1 when a character field is missing so the second test is redundant.) and if so then it is changing the value of some other CHARACTER field named NNBR.
If the goal is to replace missing values then why are you testing one variable and replacing the value of a different variable?
Also note that this code will really NOT work right if any of those variables are numeric instead of character.
Not sure why you are using CATX() when you don't actually want to insert anything between the values. Also the variable NNBR needs to be longer than four characters or to be able to hold the four zeros and the value of ID.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.