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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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