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!
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
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
;
Here is one way to do that
data have;
infile cards;
input Information $;
output;
input Date;
information = .;
output;
cards;
X1
120225
G8
180619
;
data have;
infile cards;
if mod(_n_,2) ne 0 then input Information $;
else input date;
cards;
X1
120225
G8
180619
;
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?
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.
I need a better and comprehensive sample to code and test rather than imagining what could be the likely
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.