BookmarkSubscribeRSS Feed
cjh1506
Calcite | Level 5

Hello!

 

I am creating code that takes data from an excel file I imported, and creates a very specific listed and ordered output that a data entry person can then use to enter the data directly from the output into an online database (a lot of clicking to enter things into the database, we can't just copy and paste the SAS output). I created new variables using if-then statements. If my new variable's value is blank, I want to drop the variable from the output so it shows a cleaner output for the data entry person. I do not want to drop the observation itself, just a variable, and only IF it comes up blank. I am new and figured out that I have no idea how to appropriately use "drop" statements.

 

Here is the code that I tried and obviously is wrong:

 

data mmria.rename; set mmria.rename;
if Cytomeglovirus= " " then drop;
if GroupBStrep= " " then drop;
if HIV= " " then drop;

 

Can anybody help with the syntax that I should be using? Should I be trying a different logic to achieve what I want? All of the SAS community answers I filtered through are too advanced for me, I have no idea what people are doing. Thanks a bunch!!

7 REPLIES 7
PaigeMiller
Diamond | Level 26

Do you mean drop the variable if one record for that variable is blank? Or drop the variable if all the records for that variable are blank? Or something else? Please be specific.

--
Paige Miller
cjh1506
Calcite | Level 5

Sorry! in this particular case, it does not matter, because there is only one person filtered to be in my dataset. One person with a bunch of variables. So each variable will only have 1 value.

ballardw
Super User

A general caution: Use of the same data set on input and output like this:

data mmria.rename; set mmria.rename;

Means that your output set completely replaces the source set. Depending on what you do that may result in corrupted or incomplete data.

 

HOW do you present the data to your data entry person?

SAS data sets either contain a variable or not. So what you request is not at all possible with a data set. However it may be possible to make something used by the data entry person to look like that.

 

My experience with preparing stuff for entry on websites and such (which I believe applies here) is to make a form that looks like the entry screen as much as possible so the flow between reading and entering is easy to follow.

 

Luckily I don't have to enter the data into MMRIA, if this relates to Maternal Mortality, but do get to analyze it after extracting it. So I realize this in not a trivial exercise given the number of screens and fields involved.

 

cjh1506
Calcite | Level 5

Thank you! Any recommendations to get the output to look like the mmria pages? That is definitely the goal here. It is a lot. LOL

ballardw
Super User

I might create an RTF or PDF document simulating the screen for each case.

General hint: Set options missing=' '; so the missing values appear as a blank in any Put or report column values.

 

For some of the screens that are basically multiple "lines" per record from your data set with only a couple of values I might look at data step with file print ods (to make "nice" appearance) so that you could use Put statements to have the field description text that appears on the screen in one column followed by the variable value.

 

For those bits that have rows then perhaps Proc print selecting the variables of interest.

 

Procs ODSTABLE, ODSTEXT and ODSLIST provide some options that might work for the multiple check box type of screens where you basically display the screen text as boiler plate

 

The obnoxious part is likely that you need to create a set of these forms for each observation from your data set which likely means MACRO language so you can select the specific case for each page/screen/form creator in sequence.

Reeza
Super User

I would actually not drop the variable, I'd do what @ballardw and mimic the screens. If you drop variables, then as a data entry, I now have to look at a variable name and align versus count three missing and go down the form three rows. The latter is faster mentally and for data entry. 

 

Not sure how many screens you have but if you do it for one person we can help generalize it/make it a macro for you. 

 

 

ballardw
Super User

@Reeza wrote:

I would actually not drop the variable, I'd do what @ballardw and mimic the screens. If you drop variables, then as a data entry, I now have to look at a variable name and align versus count three missing and go down the form three rows. The latter is faster mentally and for data entry. 

 

Not sure how many screens you have but if you do it for one person we can help generalize it/make it a macro for you. 

 

 


@Reeza unfortunately there are quite a few screens with mixtures of drop down lists, check boxes, radio buttons and text entry. For some of the cases (MMRIA terminology, think patient as an analogous structure) select a couple check boxes and done after entering some demographic data. For others there can be quite a few screens.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1562 views
  • 3 likes
  • 4 in conversation