Hello , I wish to create a variable "M" that extract the observations marked "bold" from days
Obs |
days |
1 |
20150320 |
2 |
20140609 |
3 |
20140807 |
4 |
20140828 |
5 |
20150418 |
6 |
20150602 |
7 |
20150625 |
8 |
20141029 |
9 |
20150220 |
10 |
20150407 |
Thank you!!!
Hoping that the days variable is a character variable
data want;
set have;
m=substr(strip(days),5,2);
run;
Hoping that the days variable is a character variable
data want;
set have;
m=substr(strip(days),5,2);
run;
Thank you!!!!
Whilst @Jagadishkatam is quite correct, that with the example you have given in a string variable, you can substr out various parts, I would also point out two things. Firstly that is a date field, and you would be best off treating it as a date. Second as that is a string field you could have anything in it, I have seen:
YY0401 or 120405
The substr would not work in these cases, unless of course you do various checks before hand. So when working with dates I always have the two components, the string value for display purposes to show it as entered, and a numeric version for processing. You could for instance do:
mnth=month(input(days,anydtdte.));
Though why you would call a date variable days is beyond me.
who cares what name I give to my variables. I just wanted to extract some number from it and some showed me, what is your issue with it.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.