BookmarkSubscribeRSS Feed
Saba1
Quartz | Level 8

 Hi

 

I need guidance to format observations of a dataset as Character variable. Actually, I have a dataset and the observations are a combination of date and character variable in various columns. See below:

 

Data Have;
infile datalines
dlm=","
missover
DSD;
input ID : $10.
	Date_Month : mmddyy10.
	Manager1 : $60.
	Manager2 : $60.
	Manager3 : $60. ;
format Date_Month mmddyy10. ;
datalines;
AB00046,01-31-2016,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,02-28-2016,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,03-31-2016,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,04-30-2016,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,05-31-2016,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,06-30-2016,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,07-31-2016,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,08-31-2016,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,09-30-2016,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,10-31-2016,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,11-30-2016,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,12-31-2016,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,01-31-2017,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,02-28-2017,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,03-31-2017,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,04-30-2017,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,05-31-2017,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,06-30-2017,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,07-31-2017,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,08-31-2017,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,09-30-2017,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,10-31-2017,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,11-30-2017,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00046,12-31-2017,[2012-01-23 -- ] Ronald Baron,[2016-01-23 -- ] Bill F. Baron,[2016-10-26 -- 2017-06-01] Tim S.
AB00050,01-31-2016,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,02-28-2016,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,03-31-2016,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,04-30-2016,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,05-31-2016,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,06-30-2016,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,07-31-2016,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,08-31-2016,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,09-30-2016,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,10-31-2016,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,11-30-2016,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,12-31-2016,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,01-31-2017,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,02-28-2017,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,03-31-2017,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,04-30-2017,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,05-31-2017,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,06-30-2017,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,07-31-2017,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,08-31-2017,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,09-30-2017,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,10-31-2017,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,11-30-2017,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
AB00050,12-31-2017,[2010-05-20 -- 2014-01-02] Tom T.,[2016-06-29 -- 2018-06-06] Sharon,
;
run;

 I have used a code to keep only Managers' names in columns which are repeating according to the dates mentioned in the brackets and also matched with the dates of Date_Month column. Now the way my data looks like is given below:

 

 

Data Want;
infile datalines
dlm=","
missover
DSD;
input ID : $10.
	Date_Month : mmddyy10.
	Manager1 : $60.
	Manager2 : $60.
	Manager3 : $60. ;
format Date_Month mmddyy10. ;
datalines;
AB00046,01-31-2016,Ronald Baron,Bill F. Baron,
AB00046,02-28-2016,Ronald Baron,Bill F. Baron,
AB00046,03-31-2016,Ronald Baron,Bill F. Baron,
AB00046,04-30-2016,Ronald Baron,Bill F. Baron,
AB00046,05-31-2016,Ronald Baron,Bill F. Baron,
AB00046,06-30-2016,Ronald Baron,Bill F. Baron,
AB00046,07-31-2016,Ronald Baron,Bill F. Baron,
AB00046,08-31-2016,Ronald Baron,Bill F. Baron,
AB00046,09-30-2016,Ronald Baron,Bill F. Baron,
AB00046,10-31-2016,Ronald Baron,Bill F. Baron,Tim S.
AB00046,11-30-2016,Ronald Baron,Bill F. Baron,Tim S.
AB00046,12-31-2016,Ronald Baron,Bill F. Baron,Tim S.
AB00046,01-31-2017,Ronald Baron,Bill F. Baron,Tim S.
AB00046,02-28-2017,Ronald Baron,Bill F. Baron,Tim S.
AB00046,03-31-2017,Ronald Baron,Bill F. Baron,Tim S.
AB00046,04-30-2017,Ronald Baron,Bill F. Baron,Tim S.
AB00046,05-31-2017,Ronald Baron,Bill F. Baron,Tim S.
AB00046,06-30-2017,Ronald Baron,Bill F. Baron,Tim S.
AB00046,07-31-2017,Ronald Baron,Bill F. Baron,
AB00046,08-31-2017,Ronald Baron,Bill F. Baron,
AB00046,09-30-2017,Ronald Baron,Bill F. Baron,
AB00046,10-31-2017,Ronald Baron,Bill F. Baron,
AB00046,11-30-2017,Ronald Baron,Bill F. Baron,
AB00046,12-31-2017,Ronald Baron,Bill F. Baron,
AB00050,01-31-2016,
AB00050,02-28-2016,
AB00050,03-31-2016,
AB00050,04-30-2016,
AB00050,05-31-2016,
AB00050,06-30-2016,Sharon
AB00050,07-31-2016,Sharon
AB00050,08-31-2016,Sharon
AB00050,09-30-2016,Sharon
AB00050,10-31-2016,Sharon
AB00050,11-30-2016,Sharon
AB00050,12-31-2016,Sharon
AB00050,01-31-2017,Sharon
AB00050,02-28-2017,Sharon
AB00050,03-31-2017,Sharon
AB00050,04-30-2017,Sharon
AB00050,05-31-2017,Sharon
AB00050,06-30-2017,Sharon
AB00050,07-31-2017,Sharon
AB00050,08-31-2017,Sharon
AB00050,09-30-2017,Sharon
AB00050,10-31-2017,Sharon
AB00050,11-30-2017,Sharon
AB00050,12-31-2017,Sharon
;
run;

I have used the following code to perform above-mentioned arramngement.:

 

 

data want;
set have;
array x{*} $ Manager1-Manager3;
array y{*} $ 32 new_Manager1-new_Manager3;

do i=1 to dim(x);
if not missing(x{i}) then do;

start=input(scan(scan(x{i},1,'[]'),1,' '),?? yymmdd10.);
if start<Date_Month then start=Date_Month;

end=intnx('month',input(scan(scan(x{i},1,'[]'),-1,' '),?? yymmdd10.),0,'e');
if end>'31dec2017'd or missing(end) then end='31dec2017'd;

if start<=Date_Month<=end then y{i}=scan(x{i},-1,'[]');
end;
end;

drop start end i;
run;

Now the issue I am facing is that SAS does not read these Managers' names as a character variable. I need to apply some coding where these managers' names will be matched with another file consisting same names. But unfortuantely these names are not Character variable so cannot be matched.

 

Plesae guide me that how to convert/format all of these observations of Manager1-Manager3 columns to be Character.

 

Thanks.

2 REPLIES 2
ballardw
Super User

Are you getting some message in the log that variables are numeric? Can you provide what you do that makes you think the names are not character?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 553 views
  • 0 likes
  • 3 in conversation