BookmarkSubscribeRSS Feed
Patelbb
Fluorite | Level 6

Hi,

 

I'm trying to write code to make it look like the attached file. However, I'm not sure what I'm doing wrong. I have no errors or warnings in my log but it is not outputting the way I would like. Any suggestions would be helpful! Thank you!

 

Log:

 

1068  **-------------------------------------------------------------------------------**;
1069  **  MERGE X_CM AND STUDYRX DATASETS TOGETHER                                        **;
1070  **-------------------------------------------------------------------------------**;
1071  data merged(drop=prefname s_cmtrt s_cmindsp s_cmindc s_cmstdtc s_cmenrf s_cmendtc s_cmany medname scrfail);
1072     merge studyrx(in=studyrx)
1073           x_cm(in=x_cm);
1074      by s_siteid s_subjid;
1075
1076      length start end $9;
1077      label start = "Start(ddMMMyyyy)"
1078            end = "End(ddMMMyyyy)";
1079
1080      ** Concatenate prefname and s_cmtrt in parentheses;
1081      Medication= trim(compress(prefname) || '(' || trim(compress(s_cmtrt)) || ')');
1082
1083      ** Create new variable for s_cmtrt;
1084      if (s_cmtrt ne ' ') then medname = Medication;
1085      else if (s_cmtrt eq ' ') then Medication = 'None';
1086
1087      ** Create new variable for s_cmindsp where missing equals s_cmindc;
1088      if (s_cmindsp ne ' ') then Indication = s_cmindsp;
1089      else if (s_cmindsp eq ' ') then Indication = s_cmindc;
1090
1091      ** Create new variable that contains numeric values of s_cmstdtc;
1092      ** If the first character of s_cmstdtc is 'U', leave numeric value missing;
1093
1094      format sort date9.;
1095      sort = input(s_cmstdtc, ??date9.);
1096      if upcase(substrn(sort,1,1))= "U" then sort = .;
1097
1098      if sort = . then start = 'Unknown';
1099      else start = s_cmstdtc;
1100
1101
1102      ** When s_cmenrf is "ONGOING" and s_cmendtc is missing, display the "ONGOING" value;
1103      if (s_cmenrf eq 'ONGOING' and s_cmendtc eq ' ') then end = 'ONGOING';
1104      else end = s_cmendtc;
1105
1106  run;
NOTE: There were 83 observations read from the data set WORK.STUDYRX.
NOTE: There were 300 observations read from the data set WORK.X_CM.
NOTE: The data set WORK.MERGED has 319 observations and 10 variables.
NOTE: DATA statement used (Total process time):
      real time           0.05 seconds
      cpu time            0.06 seconds
 
3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Hi:
All you are doing is creating the final data set WORK.MERGED. The dataset does not have titles or underlines or spanning headers, such as you show in your picture of the LISTING output.

It's hard to tell how that output was created. It does look like LISTING window output, so my guess is that it was either created with PROC REPORT or it was created with a DATA Step program and PUT statements.

You've indicated this was homework, so your professor or teaching assistant might be better resources for how you were expected to accomplish the LISTING output. You might try a PROC PRINT of your WORK.MERGED data to start to make sure that your merge worked correctly. Then you'll have to investigate other techniques.

It seems odd to me that your instructor would not explain HOW you were intended to create an output report like this from WORK.MERGED.

Cynthia
Patelbb
Fluorite | Level 6

Hi,

 

I apologize. I only copied part of my code. Here is the entire code I wrote.

 

997  **-------------------------------------------------------------------------------**;
998  ** SYSTEM OPTIONS                                                                **;
999  **-------------------------------------------------------------------------------**;
1000  options msglevel=i nodate nofmterr ls=130 ps=50;
1001
1002  **-------------------------------------------------------------------------------**;
1003  ** CREATE TITLE STATEMENTS TO BE USED WHEN DISPLAYING INFORMATION                **;
1004  **-------------------------------------------------------------------------------**;
1005  title1 'Introduction to SAS (SAS-I)
1005!                                                                 ';
1006  title2 'Homework 11: Final Project Listing 2 - Binita Patel
1006!                                                                 ';
1007
1008  **-------------------------------------------------------------------------------**;
1009  ** LIBNAME STATEMENT TO TELL SAS WHERE TO FIND DATA                              **;
1010  **-------------------------------------------------------------------------------**;
1011  libname dbraw 'C:\SAS 9.4\Raw data';
NOTE: Libref DBRAW was successfully assigned as follows:
      Engine:        V9
      Physical Name: C:\SAS 9.4\Raw data
1012
1013  **-------------------------------------------------------------------------------**;
1014  ** LIBNAME STATEMENT TO TELL SAS WHERE TO PUT FINAL DATA                         **;
1015  **-------------------------------------------------------------------------------**;
1016  libname final 'C:\SAS 9.4\Final Project\Homework 10';
NOTE: Libref FINAL was successfully assigned as follows:
      Engine:        V9
      Physical Name: C:\SAS 9.4\Final Project\Homework 10
1017
1018
1019  **-------------------------------------------------------------------------------**;
1020  ** FORMATS NEEDED FOR STUDYRX DATASET                                            **;
1021  **-------------------------------------------------------------------------------**;
1022  proc format;
1023    value trtmnt
1024         1 = 'Drug ABC'
1025         2 = 'Compare XYZ'
1026      ;
NOTE: Format TRTMNT is already on the library WORK.FORMATS.
NOTE: Format TRTMNT has been output.
1027    value $gender
1028        'M' = 'Male'
1029        'F' = 'Female'
1030      ;
NOTE: Format $GENDER is already on the library WORK.FORMATS.
NOTE: Format $GENDER has been output.
1031    value $siteid
1032        '1160' = 'Jones'
1033        '1251' = 'Brown'
1034        '1266' = 'Smith'
1035        '5503' = 'Rogers'
1036        '5610' = 'Williams'
1037        '6006' = 'Kelly'
1038      ;
NOTE: Format $SITEID is already on the library WORK.FORMATS.
NOTE: Format $SITEID has been output.
1039    value race
1040         1 = 'American Indian or Alaska Native'
1041         2 = 'Asian'
1042         3 = 'Black'
1043         4 = 'Native Hawaiian or Other Pacific Islander'
1044         5 = 'White'
1045         6 = 'Other'
1046      ;
NOTE: Format RACE is already on the library WORK.FORMATS.
NOTE: Format RACE has been output.
1047  run;
NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds

1048
1049
1050  **-------------------------------------------------------------------------------**;
1051  **  REMOVE ALL OBSERVATIONS FROM X_CM DATASET WITH NO MEDICATION                 **;
1052  **-------------------------------------------------------------------------------**;
1053  proc sort data = dbraw.x_cm(keep=s_siteid s_subjid s_cmtrt prefname s_cmindc s_cmindsp s_cmstdtc s_cmendtc s_cmenrf s_cmany)
1054             out = x_cm (where=(s_cmany ne 'NO'));
1055    by s_siteid s_subjid;
1056  run;
NOTE: There were 313 observations read from the data set DBRAW.X_CM.
NOTE: SAS sort was used.
NOTE: The data set WORK.X_CM has 300 observations and 10 variables.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

1057
1058
1059  **-------------------------------------------------------------------------------**;
1060  **  SORT STUDYRX AND KEEP ONLY NEEDED VARIABLES                                  **;
1061  **-------------------------------------------------------------------------------**;
1062  proc sort data = final.studyrx_patel(keep=s_siteid s_subjid trtgroup site agsxrc scrfail)
1063             out = studyrx;
1064    by s_siteid s_subjid;
1065  run;
NOTE: There were 83 observations read from the data set FINAL.STUDYRX_PATEL.
NOTE: SAS sort was used.
NOTE: The data set WORK.STUDYRX has 83 observations and 6 variables.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.04 seconds
      cpu time            0.01 seconds

1066
1067
1068  **-------------------------------------------------------------------------------**;
1069  **  MERGE X_CM AND STUDYRX DATASETS TOGETHER                                        **;
1070  **-------------------------------------------------------------------------------**;
1071  data merged(drop=prefname s_cmtrt s_cmindsp s_cmindc s_cmstdtc s_cmenrf s_cmendtc s_cmany medname scrfail);
1072     merge studyrx(in=studyrx)
1073           x_cm(in=x_cm);
1074      by s_siteid s_subjid;
1075
1076      length start end $9;
1077      label start = "Start(ddMMMyyyy)"
1078            end = "End(ddMMMyyyy)";
1079
1080      ** Concatenate prefname and s_cmtrt in parentheses;
1081      Medication= trim(compress(prefname) || '(' || trim(compress(s_cmtrt)) || ')');
1082
1083      ** Create new variable for s_cmtrt;
1084      if (s_cmtrt ne ' ') then medname = Medication;
1085      else if (s_cmtrt eq ' ') then Medication = 'None';
1086
1087      ** Create new variable for s_cmindsp where missing equals s_cmindc;
1088      if (s_cmindsp ne ' ') then Indication = s_cmindsp;
1089      else if (s_cmindsp eq ' ') then Indication = s_cmindc;
1090
1091      ** Create new variable that contains numeric values of s_cmstdtc;
1092      ** If the first character of s_cmstdtc is 'U', leave numeric value missing;
1093
1094      format sort date9.;
1095      sort = input(s_cmstdtc, ??date9.);
1096      if upcase(substrn(sort,1,1))= "U" then sort = .;
1097
1098      if sort = . then start = 'Unknown';
1099      else start = s_cmstdtc;
1100
1101
1102      ** When s_cmenrf is "ONGOING" and s_cmendtc is missing, display the "ONGOING" value;
1103      if (s_cmenrf eq 'ONGOING' and s_cmendtc eq ' ') then end = 'ONGOING';
1104      else end = s_cmendtc;
1105
1106  run;
NOTE: There were 83 observations read from the data set WORK.STUDYRX.
NOTE: There were 300 observations read from the data set WORK.X_CM.
NOTE: The data set WORK.MERGED has 319 observations and 10 variables.
NOTE: DATA statement used (Total process time):
      real time           0.05 seconds
      cpu time            0.06 seconds

1107
1108
1109  **-------------------------------------------------------------------------------**;
1110  ** ADD LEFT JUSTIFYING TITLES/FOOTNOTES                                          **;
1111  **-------------------------------------------------------------------------------**;
1112  title3   'Study Drug Protocol ABC-123
1112!                                                                 ';
1113  title4   'Listing 2 - Prior/Concomitant Medications
1113!                                                                 ';
1114  footnote1 'Program: C:\SAS 9.4\Final Project\Homework 11\LCMED_Patel.SAS programmed by Binita Patel on 5Dec2018
1114!                                                                 ';
1115  options pageno=1;
1116  proc report data = merged nowd center headline headskip split='`' spacing=1;
1117
1118    columns trtgroup s_siteid site s_subjid sort agsxrc Medication Indication
1119            ("-Medication Dates-" start end);
1120
1121      define trtgroup        / order   width=15 left   'Treatment`  Group' format=trtmnt.   order=internal flow;
1122      define s_siteid        / order   noprint                                              order=internal;
1123      define site            / order   width=14 left   'Site'                               order=internal;
1124      define s_subjid        / order   width=7  left   'Subject `  Number'                  order=internal;
1125      define sort            / order   noprint;
1126      define agsxrc          / group   width=14 left   'Age-Sex-Race';
1127      define Medication      / display width=17 left   'Medication'                                        flow;
1128      define Indication      / display width=17 left   'Indication'                                        spacing=3 flow;
1129      define start           / display width=16 left   'Start(ddMMMyyyy)';
1130      define end             / display width=18 left   'End(ddMMMyyyy)';
1131
1132      break after trtgroup   / page;
1133      break after site   / skip;
1134  run;
NOTE: Groups are not created because the usage of Medication is DISPLAY. To avoid this note, change all GROUP variables to ORDER
variables.
NOTE: Multiple concurrent threads will be used to summarize data.
NOTE: There were 319 observations read from the data set WORK.MERGED.
NOTE: PROCEDURE REPORT used (Total process time):
      real time           0.06 seconds
      cpu time            0.04 seconds

1135  title3;
1136  footnote;
 
Cynthia_sas
SAS Super FREQ
Hi: Thanks for posting the rest of your code. So, do you see the NOTE about "Groups are not created ...." That would be my suggestion for the first place to start debugging.
Cynthia

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 915 views
  • 2 likes
  • 2 in conversation