how to set when not missing values into new variable and varible name into new variable by using array
ex: below table
| ID | subject | prop | cord | kacr | Oldvar | FiledVal |
| 102 | aaa | asw | prop | asw | ||
| 102 | aaa | wewe | cord | wewe | ||
| 102 | aaa | eer | kacr | eer | ||
| 105 | bbb | ddd | cord | ddd | ||
| 105 | bbb | ss | kacr | ss | ||
| 105 | bbb | |||||
| 108 | ccc | qee | prop | qee | ||
| 108 | ccc | ss | prop | ss | ||
| 108 | ccc | asdsa | kacr | asdsa |
Define an array with the variables prop, cord and kacr. Use a loop to check the array, use vname (or vnamex) to set oldvar, assuming that setting FieldVar is not a problem.
Untested code:
data want;
set have;
length OldVar $ 32 FiledVal $ 100;
array values[1:3] prop cord kacr;
do i = 1 to dim(values);
if not missing(values[i]) then do;
OldVar = vnamex(values[i]);
FiledVal = values[i];
/* maybe leave loop here */
end;
end;
run;
1. Define an array
2. Use COALESCEC to find the value, since you only have one per row this is fine.
3. Use WHICHC to find the index of the variable.
4. Use VNAME to get the name of the variable.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.