BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pmpradhan
Quartz | Level 8

I have a character variable 'Information' with the following values:

 

Information

X1

120225

G8

180619

 

Based on Information variable, I want to create two variables as follows:

Information    Date

X1                   .

.                     120225          

G8                  .

.                     180619

 

Please help!

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @pmpradhan  try this

 

data have;
input Information $;
cards;
X1
120225
G8
180619
;

data want;
set have;
if anyalpha(information)=0 then date=input(information,yymmdd8.);
if date then call missing(information);
format date yymmdd8.;
run;

My assumptions:

Your source is a sas dataset

Date values are all numbers

Information value may be a mix of numbers/other chars 

View solution in original post

8 REPLIES 8
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

are you sure that you want the null values as the sample want has?

 

or do you want this

data have;
infile cards;
input Information $  Date;
cards;
X1
120225
G8
180619
;
pmpradhan
Quartz | Level 8
Yes I want them as the null values as the sample want has.
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

Here is one way to do that

data have;
infile cards;
input Information $;
output;
input Date;
information = .;
output;
cards;
X1
120225
G8
180619
;

 

novinosrin
Tourmaline | Level 20
data have;
infile cards;
if mod(_n_,2) ne 0 then input Information $;
else input date;
cards;
X1
120225
G8
180619
;
pmpradhan
Quartz | Level 8

Information is one of the many variables in my SAS dataset. The observations are more than couple hundreds. Is there something better than infile statement? where I don't have to enter the variable values? 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

a larger sample representing what you have with more of the variables you are speaking about now.  also at what point do the null values get reset based on your want sample that is unclear now since you say there are many variables.

 

Please don't play the part of a manager if your trying to learn to code.

 

this link may assist you

https://communities.sas.com/t5/New-SAS-User/Good-SAS-Course-in-Coursera/m-p/507864#M1531

the course if free in audit.

 

novinosrin
Tourmaline | Level 20

I need a better and comprehensive sample to code and test rather than imagining what could be the likely

novinosrin
Tourmaline | Level 20

Hi @pmpradhan  try this

 

data have;
input Information $;
cards;
X1
120225
G8
180619
;

data want;
set have;
if anyalpha(information)=0 then date=input(information,yymmdd8.);
if date then call missing(information);
format date yymmdd8.;
run;

My assumptions:

Your source is a sas dataset

Date values are all numbers

Information value may be a mix of numbers/other chars 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 1422 views
  • 1 like
  • 3 in conversation