BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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.

pic.png

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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;
PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

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;
PG
mkeintz
PROC Star

@sahoositaram555 

 

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.

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 842 views
  • 1 like
  • 3 in conversation