Hi. I have two variables as following below.
ID Year
US2007025948 2007
What I want to do is that if year (2007) equals to the third to the sixth digit of ID (US2007025948), delete this observation.
What code do I need to use? Thanks.
if put(year, 4.) = substr(id, 3, 4) then delete;
This assumes year is numeric and ID is character. If it's otherwise you'll need to modify the functions a little bit, but in general that's what you need. It can be modified to be in a WHERE clause, or for SQL or a data step as needed as well.
@dapenDaniel wrote:
Hi. I have two variables as following below.
ID Year
US2007025948 2007
What I want to do is that if year (2007) equals to the third to the sixth digit of ID (US2007025948), delete this observation.
What code do I need to use? Thanks.
if put(year, 4.) = substr(id, 3, 4) then delete;
This assumes year is numeric and ID is character. If it's otherwise you'll need to modify the functions a little bit, but in general that's what you need. It can be modified to be in a WHERE clause, or for SQL or a data step as needed as well.
@dapenDaniel wrote:
Hi. I have two variables as following below.
ID Year
US2007025948 2007
What I want to do is that if year (2007) equals to the third to the sixth digit of ID (US2007025948), delete this observation.
What code do I need to use? Thanks.
Year is also character variable.
if year=substr(id, 3, 4) then delete;
Is it correct?
there is no error message so I think it works.
I checked the output. The code works well. Thanks.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.