DATA Step, Macro, Functions and more

How to remove the column with blank and . ?

Reply
Super Contributor
Posts: 297

How to remove the column with blank and . ?

[ Edited ]

Hello:

 

First, I would like to looking for the columns containing '.' .   Then I would like to remove the whole column containing '.', such as bd_dx_3 and if_img_7.   In addtions, I would like to looking for the column with blank which nothing in it.  (I would like to add some blanks in the test file,  but I don't know how to SAS read the blanks.)     Thanks.

 

data test;

input Name $ bd_dx_1-bd_dx_6 State_ID_1-State_ID_4 If_img_1-If_img_8;

cards;

A 0.57 0.015 . 0.927 0.16 0.336 0.153 0.461 0.342 0.056 0.698 0.165 0.019 0.5

0.413 0.184 . 0.689

B 0.512 0.811 . 0.293 0.42 0.223 0.809 . 0.483 0.714 0.836 0.231 0.314 0.057

0.177 0.698 . 0.384

C 0.406 0.313 . 0.234 0.759 0.328 0.895 0.004 0.659 0.209 0.449 0.927 0.343 0.368

0.776 0.114 . 0.316

D 0.995 0.69 . 0.491 0.511 0.288 0.411 0.712 0.17 0.055 0.233 0.465 0.264 0.615

0.807 0.614 . 0.262

E 0.193 0.144 . 0.576 0.033 0.51 0.999 . 0.392 . 0.852 0.865 0.96 0.31

0.267 0.998 . 0.042

F 0.686 0.103 . 0.173 0.538 0.209 0.887 0.824 0.035 0.426 0.642 0.998 0.884 0.525

0.737 0.52 . 0.292

;

run;

Super User
Posts: 17,872

Re: How to remove the column with blank and . ?

[ Edited ]

Use PROC MEANS or PROC FREQ to the number of missing. If it's the entire N, create a macro variable with the list of variables and add them into a DROP statement.

 

And a quick search will provide an abundance of examples of how this can be achieved.

https://communities.sas.com/t5/SAS-Procedures/How-to-drop-a-variable-as-long-as-it-contains-missing-...

Ask a Question
Discussion stats
  • 1 reply
  • 75 views
  • 0 likes
  • 2 in conversation