BookmarkSubscribeRSS Feed
kuridisanjeev
Quartz | Level 8

Hi...

I am having the  following code

data xx;

input folder $ date ddmmyy10.;

format date ddmmyy10.;

cards;

week1 21/05/2012

week2 21/05/2011

week3 21/05/2010

;

run;

data yy;

set xx;

format week1 week2 week3 date9.;

if folder = 'week1'  then week1 = date;

if folder = 'week2' then week2 = date;

if folder = 'week3' then week3 = date;

run;

I want to display  '  '(space)  in the place of ' . '(period) , whenever the date is missing the Week1,week2,week3 columns .

Note:I don't want to use any IF conditions.

Thanks in advance ..

Regards,

Sanjeev.K

11 REPLIES 11
Amir
PROC Star

Hi Sanjeev,

You could try using the following options statement before your code:

options missing=' ';

I wasn't sure if you wanted to replace your if statements as you noted, but if that is the case then you could use the select statement.

Regards,

Amir.

kuridisanjeev
Quartz | Level 8

Hi Amir..

IF i use Missing='' option,other numeric variables(which are not shown in the code)  also effected.but i want to keep periods in numeric variables when there is no data.

Thanks..

Sanjeev.K

Amir
PROC Star

Hi Sanjeev,

I'm not sure how some numeric data can have missing represented by a blank and others be represented by a period at the same time

Perhaps consider using some default value which is not going to appear in your input data.

I did find this forum question https://communities.sas.com/message/139151#139151 but was unable to get the solution to fit around your problem.

Regards,

Amir.

Message was edited by: Amir Malik - rephrase.

LinusH
Tourmaline | Level 20

To avoid your if-statements, use PROC TRANSPOSE.

I think as Amir it's hard to have different missing chars in he same report.

perhaps (untested!) you can create a new format based on ddmmyy, where you explicitly set the missing to space...?

Data never sleeps
LinusH
Tourmaline | Level 20

Another easier option is to convert your date columns to char prior to reporting, and then replace . with space.

Data never sleeps
yaswanthj
Calcite | Level 5

Could you please provide what option is there.

Thanks & Regards,

Yaswanth J.

kuridisanjeev
Quartz | Level 8

Hi LinusH..

Did't get you completely...

Can you please write sample code for my above example.??

That make sense..

Thanks..

Sanjeev.K

LinusH
Tourmaline | Level 20

If you report directly from your import data, use char informat directly:

input $date char10.;

The there will never be a period (unless your source data contains it...)

PROC TRANSPOSE, see online doc, stuffed with examples...

Data never sleeps
Patrick
Opal | Level 21

If there is not a very good reason then I wouldn't store dates as strings but as SAS date values. If you're using strings then one of the issues you're facing in reports is the sort order of the dates in your reports.

I believe using a user defined format as posted earlier will cover the requirement without causing new issues.

Patrick
Opal | Level 21

You could create your own format based on an existing one like done in below code:

proc format;
  value My_ddmmyy
    .=' '
    other=[ddmmyy.]
  ;
run;

data have;
  input folder $ date ddmmyy10.;
  format date My_ddmmyy10.;
cards;
week1 21/05/2012
week2
week3 21/05/2010
;
run;

ballardw
Super User

Patrick's response is a very good idea in general. When only one or two values need special appearance make a custom version of the format like this. It can save a great deal of complex coding.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 11 replies
  • 1120 views
  • 3 likes
  • 6 in conversation