I have a fllowing sample datasetwhich contains all character variables
(subject, F1, F2,F3, F4, F5, F6):
subject F1 F2 F3 F4 F5 F6
------- -- -- -- ----------- ---- -----------
10002 4 7 9 9 10 9
10001 0 3 4 Total (JD) 7 Total (PP)
10006 8 8 8 0 9 9
I need to delete those columns/vraiables if those vraiables have any value as "Total (JD)"
or "Total (PP)"
so the result dataset should be as below:
subject F1 F2 F3 F5
------- -- -- -- --
10002 4 7 9 10
10001 0 3 4 7
10006 8 8 8 9
Means the remaining varibales would be (subject, F1, F2, F3, F5).
Thanks you so much from the bottom of my heart.
You can make use of arrays for this type of work, see sample code below. For each obs loop through all values and check for the text, if text is found get variable name, compare to a list and add if not found.
How about this one :
data have; infile cards dlm=","; input subject : $12. F1 : $12. F2 : $12. F3 : $12. F4 : $12. F5 : $12. F6 : $12. ; cards; 10002, 4, 7, 9, 9, 10, 9 10001, 0, 3, 4, Total (JD), 7, Total (PP) 10006, 8, 8, 8, 0, 9, 9 10007, 8, 8, 8, Total (JD), 9, 9 10008, 8, 8, 8, 0, Total (PP), 9 ; run; proc sql noprint; select cat('sum(',strip(name),'="Total (JD)" or ',strip(name),'="Total (PP)") as ',strip(name)) into : list separated by ',' from dictionary.columns where libname='WORK' and memname='HAVE' and upcase(name) like 'F%'; create table temp as select &list from have; quit; data _null_; set temp; length drop $ 200; array x{*} _numeric_; do i=1 to dim(x); if x{i} ne 0 then drop=catx(' ',drop,vname(x{i})); end; call symputx('drop',drop); run; data want; set have(drop= &drop ); run;
Xia Keshan
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.