Hi,
I have a dataset with 7 individuals (ID) and 2 households (FAM). In addition, I have two variables, Ink and Disp. Ink shows the individual's income while Disp shows the households' disposable income. Disp thus repeats itself. I want the variable disp to be kept for the first individual in the household and get a value missing for the rest of the individuals in the household. Below is the code that shows what I have and how I want it to be. thank you!
DATA HAVE;
INPUT ID FAM INK DISP;
DATALINES;
1 1 50 60
2 1 100 60
3 1 200 60
4 2 500 250
5 2 700 250
6 2 0 250
7 2 0 250
;
RUN;
DATA WANT;
INPUT ID FAM INK DISP;
DATALINES;
1 1 50 60
2 1 100 .
3 1 200 .
4 2 500 250
5 2 700 .
6 2 0 .
7 2 0 .
;
RUN;
data want;
set have;
by fam;
if not first.fam then disp = .;
run;
data want;
set have;
by fam;
if not first.fam then disp = .;
run;
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!
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.