Hi team,
I am creating a new variable during reading the csv file but somehow not getting any idea to do so .so I need to create 2 variables one is the date_Curr which will get the current datetime() second column is yrmnt value will be &ymt.
can you please help.
Kajal
libname work2 '/work/sas/data'; data work2.sample; infile "/work/sas/sample.csv" delimiter = "," dsd truncover missover firstobs=2; Length cust_id cust_name ; informat cust_id 8.; informat cust_name $5.; format cust_id 8.; format cust_name $5.; input cust_id cust_name ; run;
libname work2 '/work/sas/data';
data work2.sample;
infile "/work/sas/sample.csv"
delimiter = ","
dsd
truncover
missover
firstobs=2;
Length
cust_id
cust_name
;
informat cust_id 8.;
informat cust_name $5.;
format cust_id 8.;
format cust_name $5.;
date_curr = datetime();
format date_curr datetime.;
yrmnt="&ymt.";
input
cust_id
cust_name
;
run;
EDIT: added format for datetime.
Thanks @Reeza also is there a way if we can change the type of column cust_id in the same program ? or I need to write another step to modify the dataset?
You can change the type/format/length as you read it in and save it.
I would highly suggest you comment your code so you understand what each section is doing, that makes it a bit easier to see where you need to modify it.
Just add any assignment statements you need to the DATA step.
Why are you naming variable DATE_CURR if you want it to contain DATETIME values instead of DATE values? Either place the DATE into the variable or rename the variable.
Is the variable YMNT supposed to be numeric or character? What types of strings is the macro variable YMT going to contain?
libname work2 '/work/sas/data';
data work2.sample;
infile "/work/sas/sample.csv"
delimiter = ","
dsd
truncover
firstobs=2
;
length
cust_id 8
cust_name $5
curr_date 8
curr_datetime 8
ymnt 8
;
input
cust_id
cust_name
;
curr_date = date();
curr_datetime = datetime();
ymnt = &ymt;
format curr_date date9. curr_datetime datetime19.;
run;
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!
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.