Hi,
I have a dateset where I need to keep the columns those are named Sepstrata1, Sepstrata2, Sepstrata3 which should have only first record as NON-EMPTY while values from second rows till End rows should go missing. Would need help to make a code to make these columns missing DYNAMICALLY.
data plot_data_fin; set plot_datafin ; if _n_ =1 then set transposed_gen_mod; array vars{3} sepsrata:; do i=1 to 3; if row ~=1 then vars{i}=" "; end; run; All the columns in the picture comes from transposed_gen_mod. While I want other columns to be carrying the last values, except the Sepstrata: ones where I would like to keep only the first record and other rows should go missing.
You were quite close...
data plot_data_fin;
set plot_datafin ;
if _n_ =1 then set transposed_gen_mod;
else call missing(of sepsrata:);
run;
You were quite close...
data plot_data_fin;
set plot_datafin ;
if _n_ =1 then set transposed_gen_mod;
else call missing(of sepsrata:);
run;
What @PGStats has demonstrated to you is one of the fundamental consequences of conditional set statements (i.e. "if _n_=1 then set transposed_gen_mod;" ).
The variables retrieved for each execution of a SET (or MERGE) statement are, by default, retained. We usually don't recognize this because SET is usually not conditionally executed, so for each iteration of the data step, the current SET replaces variables retrieved by the same SET in the prior iteration. That's why you are advised to use a "call missing" after observation 1.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.