DATA Step, Macro, Functions and more

DROP Statement: Only drop elements that are in an array

Reply
New Contributor
Posts: 2

DROP Statement: Only drop elements that are in an array

[ Edited ]

New SAS user here. I'm attempting to convert character values to numeric values using arrays. After the conversion, I would like to DROP all the fields that comprise my initial array (character values). Is there a way to drop only the variables that appear in my character values array?

 

data test;
	infile datalines delimiter=','; 
	input col1 $ col2 $ col3 $ oddball $;
	format col1--oddball $char100.;
	datalines;
1,2,0,a
2,3,0,b
3,4,0,c 
		;
run;

data test2;
	set test;

	format newCol1-newCol3 best.;

    array myarray Col1-Col3;
    array myNewarray newCol1-newCol3;
    do i=1 to dim(myarray);
           myNewarray[i]= input(myarray[i],best.);
    end;
    drop myarry[*];
run;

I'm receiving the error at the DROP statement.

Super User
Posts: 23,262

Re: DROP Statement: Only drop elements that are in an array

Posted in reply to jmobball34

I don’t think you can reference an array in the DROP statement, but you can list your variables the way you did in the array statement:

 

Drop col1-col3;
Ask a Question
Discussion stats
  • 1 reply
  • 70 views
  • 0 likes
  • 2 in conversation