I have a table which contains both character and numeric values and I want character values in one table and numeric values in another table how to do this.??
data N(keep=_NUMERIC_)
C(keep=_CHARACTER_);
set SASHELP.CLASS;
run;
Do something like this
data have;
input Char1 $ Char2 $ Num1 Num2;
datalines;
ten twenty 10 20
thirty forty 30 40
fifty sixty 50 60
;
proc sql noprint;
select name into :charVars separated by " " from dictionary.columns
where libname="WORK" and memtype="DATA" and memname="HAVE" and type="char";
select name into :numVars separated by " " from dictionary.columns
where libname="WORK" and memtype="DATA" and memname="HAVE" and type="num";
quit;
%put &charVars.;
%put &numVars.;
data CharacterVars;
set have;
keep &charVars.;
run;
data NumericVars;
set have;
keep &numVars.;
run;
can we do this in data step without using macros.??
data CharacterVars;
set have;
keep _numeric_;
run;
data NumericVars;
set have;
keep _character_;
run;
data N(keep=_NUMERIC_)
C(keep=_CHARACTER_);
set SASHELP.CLASS;
run;
Thanks for the solution
Whilst you have the answer, I would ask why you want to do this? I suspect you want to do some procedure on just num vars or something like that, in which case you don't need to. You can use the automatic _numeric_ and _character_ to refere to either blocks pretty much anywhere, e.g.:
proc means data=have; var _numeric_; run;
No need to split.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.