BookmarkSubscribeRSS Feed
megha_sinha
Calcite | Level 5

Hi team,

 

My inputa dat set is as below mentioned in sas code:

So input data set contains amt column as character data type(as it is having both numeric and character values)

but in final report i want to show numeric rows of column amt as numeric with some format and charcater rows as character.

expected outp

data tmp;
name="megha";
amt="17000000.03";
flg="N";
output;
name="Alok";
amt="12200000.04";
flg="N";
output;
name="Bittu";
amt="Bit";
flg="C";
output;
name="Cittu";
amt="Cit";
flg="C";
output;
run;

ut is attached in excel sheet.

 

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

I am afraid it is unsafe to download office files, so I can't see your output.  If you want to see mixed formats in one column in your output,then the simplest way is to create a character field to hold all the data, and then set each of your data items into that, for example:

data want;
  set have;
  length output_column $50;
  output_column=put(number_var,z5.);
  output;
  output_column=text_variable;
  output;
  output_column=put(date_variable,date9.);
  output;
  ...
run;

So in each case I take a variable, convert it to text (if needed) and store the result in output_column.  Then that output column can be displayed in your report.  In SAS (as with all structured data) you cannot have a column with mixed types, but text kind of covers everything.

Shmuel
Garnet | Level 18

You better split the amt variable into two variables: amt_n for numeric and amt_c for alphanumeric.

 

If you can't do it  on yout input then you can do it like:

       data temp;

           set have;

                 length amt_n 8 amt_c $8;  /* adapt length to max number of characters  */

                 if indexc(locase(amt),'abcdefghijklmnopqrstuvwxyz') > 0

                    then amt_c = amt;

                    else amt_n = input(amt, best 12.2);   /* addapt informat as needed */

      run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 1446 views
  • 0 likes
  • 3 in conversation