BookmarkSubscribeRSS Feed
ballardw
Super User

Instead of writing long if statement use the IN operator.

For example don't use this:

if _CaseNumber=10.01867 or _CaseNumber=10.02274 or _CaseNumber=11.01668 or _CaseNumber=11.01889 or _CaseNumber=11.03437 or _CaseNumber=12.00581 then hemoscore=2; 

Use:

if _CaseNumber in (10.01867, 10.02274, 11.01668, 11.01889, 11.03437, 12.00581) then hemoscore=2; 

If using character variables then put the values in quotes.

uwmsasuser
Calcite | Level 5

Thank you. That is a helpful shortcut to know.

Tom
Super User Tom
Super User

Perhaps this little in sight into how SAS works when creating a new version of a dataset will help with your understanding of what is happening.  On Windows and Unix SAS datasets are stored in files with the extension '.sas7bdat'.  When you tell SAS to create a new dataset (file) with the same name as an old one it first creates to whole new dataset (file) using a temporary filename.  It then deletes the old file and renames to newly created file so that it has the expected name.  This way if there is an issue in the middle you do not lose both the old and the new versions of the file.

So in your second attempt to create PLAY2 you are starting completely over again. Just because this step is going to overwrite the old PLAY2 doesn't mean that it will know anything about that old dataset, UNLESS you tell to start from that version by referencing it in the SET statement.

Tom
Super User Tom
Super User

The SET statement tells the data step what data to use as INPUT.  Then name on the DATA statement is the one tells it what dataset to use as OUTPUT. Just like with other programs such as WORD or EXCEL if you save data with the same name it overwrites the existing file with that name.

You might want to do your exploratory work using WORK datasets and only write permanent dataset when you have figured out what data you want to actually save.

Also you should look into perhaps creating flag variables on your datasets so that you do not need to "delete" records.  Instead you can just run the analysis against the whole file and use the WHERE statement to subset the records.

proc print data=sashelp.class ;

  where sex='M';

run;

Some of what you appear to be doing is data cleaning. Another old style process is to create transaction files that you can then merge with the master file using the UPDATE statement.  That way you can keep your master file and also have a the transaction file as a nice record of the changes that you have made.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 18 replies
  • 1046 views
  • 6 likes
  • 4 in conversation