BookmarkSubscribeRSS Feed
SASACC
Calcite | Level 5
Hi ,

Please help me in coding below logic:

Read the dataset and if dataset contains any numeric column then convert that column into character column.
Ex:
Dataset has two columns A and B.
A numeric 8 ;
B character 1 ;

so here Column A should become character column with length 256.

Please note that we dont have fixed columns meaning dataset is created in a seprate program which doest have fixed columns.

Many Thanks for your help.
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
A DATA step should satisfy your rqmt here - after inputting SAS CHARACTER variables to start with an INPUT Statement, then using various SAS functions like ANYALPHA / ANYDIGIT to test your strings, followed by the INPUT function to convert, as required, from character to numeric. Lastly, consider the use of KEEP / DROP to only capture the SAS variables you require for the SAS output file/member/table.

Below are a few examples of Google search arguments you can make use of, for searching the SAS support http://support.sas.com/ website, which has much (free!) information including SAS-hosted DOC and supplemental technical / conference papers on this type of learning - topic.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search arguments, this topic / post:

intro data step programming site:sas.com

intro input function site:sas.com

intro anyalpha anydigit function site:sas.com
data_null__
Jade | Level 19
Are you sure you really want to do this? Do you really want to use a macro?

[pre]
data class / view=class;
set sashelp.class;
length dummy $32; /*or $256*/
retain dummy ' ';
run;
proc transpose data=class out=class2(where=(_name_ ne 'dummy'));
var dummy _numeric_;
by name sex;
run;
proc transpose data=class2 out=class0(drop=_:);
var col1;
by name sex;
run;
proc contents varnum;
run;
proc print;
run;
[/pre]
ArtC
Rhodochrosite | Level 12
If you really do want to use a more complicated macro solution take a look at Example A1.6.4 in Carpenter's Complete Guide to the SAS Macro Language, Second Edition

sas-innovate-wordmark-gradient-background 3.pngSAS Innovate

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2462 views
  • 0 likes
  • 4 in conversation