I would like to apply the total count('case_id'), while grouping by the Item.
This was my previous ask DAX Measure to calculate aggregate data, but group by Case ID. This gave me the total count('case_id') by sub_item.
Measure =
VAR datesSelection =
DATE(
YEAR(SELECTEDVALUE('Date Selection'[DateWoTime]))
,MONTH(SELECTEDVALUE('Date Selection'[DateWoTime]))
,DAY(SELECTEDVALUE('Date Selection'[DateWoTime]))
)
VAR devicesTotal =
CALCULATETABLE (
VALUES ( Outages[Sub_Item] ),
ALLSELECTED ( Outages ),
Outages[DATE] >= datesSelection,
VALUES ( Outages[Sub_Item] )
)
var counts =
CALCULATE (
COUNT( Outages[CASE_ID] ),
ALLSELECTED( Outages ),
Outages[Sub_Item] IN devicesTotal
)
return
counts
I'm getting this.
| Item | Sub_Item | TYPE | Case ID | Date | Measure |
|-------|----------|------|------------|------------------|---------|
| 701ML | abc | TFUS | 1312937981 | 7/16/19 7:18:00 | 1 |
| 702ML | abc | TFUS | 1312958225 | 7/16/19 11:13:00 | 1 |
| 702ML | abc1 | TFUS | 1312957505 | 7/16/19 11:03:00 | 1 |
| 702ML | abc2 | TFUS | 1312954287 | 7/16/19 10:24:00 | 1 |
| 702ML | abc3 | TFUS | 1312938599 | 7/16/19 7:28:00 | 1 |
| 702ML | abc4 | TFUS | 1290599620 | 5/25/18 15:43:00 | 2 |
| 702ML | abc4 | TFUS | 1312950297 | 7/16/19 9:43:00 | 2 |
| 708BI | abc | TFUS | 1312947288 | 7/16/19 9:13:00 | 1 |
| 712BI | abc | TFUS | 1312944078 | 7/16/19 8:30:00 | 1 |
| 785DL | abc | TFUS | 1312937536 | 7/16/19 7:12:00 | 1 |
| 786DL | abc | TFUS | 1312992583 | 7/16/19 14:59:00 | 1 |
| 791DI | abc | LFUS | 1289094627 | 4/28/18 20:07:00 | 2 |
| 791DI | abc | LFUS | 1312958972 | 7/16/19 11:17:00 | 2 |
| 791DI | abc1 | LFUS | 1313005237 | 7/16/19 14:00:00 | 2 |
| 791DI | abc2 | RCLR | 1290324328 | 5/22/18 15:36:00 | 2 |
| 841JU | abc | TFUS | 1312955016 | 7/16/19 10:32:00 | 1 |
| 841JU | abc1 | SBKR | 1288688911 | 4/15/18 10:09:56 | 2 |
| 841JU | abc1 | SBKR | 1312961007 | 7/16/19 11:46:24 | 2 |
| 871NI | abc2 | TFUS | 1304308511 | 3/24/19 19:13:00 | 2 |
| 871NI | abc | TFUS | 1313015455 | 7/16/19 18:39:00 | 2 |
| 917CN | abc | TFUS | 1312945831 | 7/16/19 8:58:00 | 1 |
| 918CN | abc | LFUS | 1292611263 | 6/30/18 9:41:00 | 2 |
| 918CN | abc | LFUS | 1313006283 | 7/16/19 17:03:00 | 2 |
| 922DU | abc | TFUS | 1312987081 | 7/16/19 14:20:00 | 1 |
| 922DU | abc1 | TFUS | 1313005803 | 7/16/19 17:04:00 | 1 |
| 922DU | abc2 | TFUS | 1313003541 | 7/16/19 16:42:00 | 1 |
| 931LF | abc | TFUS | 1312972165 | 7/16/19 12:46:00 | 1 |
When I would like to get this.
| Item | Sub_Item | TYPE | Case ID | Date | Measure |
|-------|----------|------|------------|-----------------|---------|
| 701ML | abc | TFUS | 1312937981 | 7/16/2019 7:18 | 1 |
| 702ML | abc | TFUS | 1312958225 | 7/16/2019 11:13 | 6 |
| 702ML | abc1 | TFUS | 1312957505 | 7/16/2019 11:03 | 6 |
| 702ML | abc2 | TFUS | 1312954287 | 7/16/2019 10:24 | 6 |
| 702ML | abc3 | TFUS | 1312938599 | 7/16/2019 7:28 | 6 |
| 702ML | abc4 | TFUS | 1290599620 | 5/25/2018 15:43 | 6 |
| 702ML | abc4 | TFUS | 1312950297 | 7/16/2019 9:43 | 6 |
| 708BI | abc | TFUS | 1312947288 | 7/16/2019 9:13 | 1 |
| 712BI | abc | TFUS | 1312944078 | 7/16/2019 8:30 | 1 |
| 785DL | abc | TFUS | 1312937536 | 7/16/2019 7:12 | 1 |
| 786DL | abc | TFUS | 1312992583 | 7/16/2019 14:59 | 1 |
| 791DI | abc | LFUS | 1289094627 | 4/28/2018 20:07 | 4 |
| 791DI | abc | LFUS | 1312958972 | 7/16/2019 11:17 | 4 |
| 791DI | abc1 | LFUS | 1313005237 | 7/16/2019 14:00 | 4 |
| 791DI | abc2 | RCLR | 1290324328 | 5/22/2018 15:36 | 4 |
| 841JU | abc | TFUS | 1312955016 | 7/16/2019 10:32 | 3 |
| 841JU | abc1 | SBKR | 1288688911 | 4/15/2018 10:09 | 3 |
| 841JU | abc1 | SBKR | 1312961007 | 7/16/2019 11:46 | 3 |
| 871NI | abc2 | TFUS | 1304308511 | 3/24/2019 19:13 | 2 |
| 871NI | abc | TFUS | 1313015455 | 7/16/2019 18:39 | 2 |
| 917CN | abc | TFUS | 1312945831 | 7/16/2019 8:58 | 1 |
| 918CN | abc | LFUS | 1292611263 | 6/30/2018 9:41 | 2 |
| 918CN | abc | LFUS | 1313006283 | 7/16/2019 17:03 | 2 |
| 922DU | abc | TFUS | 1312987081 | 7/16/2019 14:20 | 3 |
| 922DU | abc1 | TFUS | 1313005803 | 7/16/2019 17:04 | 3 |
| 922DU | abc2 | TFUS | 1313003541 | 7/16/2019 16:42 | 3 |
| 931LF | abc | TFUS | 1312972165 | 7/16/2019 12:46 | 1 |
You need to specify what level you are aggregating at in your measure. Currently, you are aggregating at the Sub_Item level.
To aggregate at the Item level, simply replace Sub_Item with Item in your measure.
Related
I want to add more rows using the Query editor (Power query/ M Query) in only the Start Date and End Date column:
+----------+------------------+--------------+-----------+-------------+------------+
| Employee | Booking Type | Jobs | WorkLoad% | Start Date | End date |
+----------+------------------+--------------+-----------+-------------+------------+
| John | Chargeable | CNS | 20 | 04/02/2020 | 31/03/2020 |
| John | Chargeable | CNS | 20 | 04/03/2020 | 27/04/2020 |
| Bernard | Vacation/Holiday | SN | 100 | 30/04/2020 | 11/05/2020 |
| Bernard | Vacation/Holiday | Annual leave | 100 | 23/01/2020 | 24/02/2020 |
| Bernard | Chargeable | Tech PLC | 50 | 29/02/2020 | 30/03/2020 |
+----------+------------------+--------------+-----------+-------------+------------+
I want to find the MIN(Start Date) and MAX(End Date) and then append the range of start to end dates to this table only in the Start Date and End Date column in the Query Editor (Power Query/ M Query). Preferrable if I can create another table2 duplicating the original table and append these rows.
For example:
+----------+------------------+--------------+-----------+-------------+------------+
| Employee | Booking Type | Jobs | WorkLoad% | Start Date | End date |
+----------+------------------+--------------+-----------+-------------+------------+
| John | Chargeable | CNS | 20 | 04/02/2020 | 31/03/2020 |
| John | Chargeable | CNS | 20 | 04/03/2020 | 27/04/2020 |
| Bernard | Vacation/Holiday | SN | 100 | 30/04/2020 | 11/05/2020 |
| Bernard | Vacation/Holiday | Annual leave | 100 | 23/01/2020 | 24/02/2020 |
| Bernard | Chargeable | Tech PLC | 50 | 29/02/2020 | 30/03/2020 |
| | | | | 23/01/2020 | 23/01/2020 |
| | | | | 24/01/2020 | 24/01/2020 |
| | | | | 25/01/2020 | 25/01/2020 |
| | | | | 26/01/2020 | 26/01/2020 |
| | | | | 27/01/2020 | 27/01/2020 |
| | | | | 28/01/2020 | 28/01/2020 |
| | | | | 29/01/2020 | 29/01/2020 |
| | | | | 30/01/2020 | 30/01/2020 |
| | | | | 31/01/2020 | 31/01/2020 |
| | | | | ... | ... |
| | | | | 11/05/2020 | 11/05/2020 |
+----------+------------------+--------------+-----------+-------------+------------+
The List.Dates function is pretty useful here.
Generate the dates in your range, duplicate that to two columns and then append.
let
StartDate = List.Min(StartTable[Start Date]),
EndDate = List.Max(StartTable[End Date]),
DateList = List.Dates(StartDate, Duration.Days(EndDate - StartDate), #duration(1,0,0,0)),
DateCols = Table.FromColumns({DateList, DateList}, {"Start Date", "End Date"}),
AppendDates = Table.Combine({StartTable, DateCols})
in
AppendDates
I want to disable a country from country list of my register page ,settings or anywhere country is shown on My Openedx App (OpenEdx is a django based system). But i cannot find country list for removing the country . Where locate the countries? I need to remove it . Django uses django_countries.fields class
Those are my tables on mysql :
+------------------------------------------------------------------+
| Tables_in_edxapp |
+------------------------------------------------------------------+
| api_admin_apiaccessconfig |
| api_admin_apiaccessrequest |
| api_admin_historicalapiaccessrequest |
| assessment_aiclassifier |
| assessment_aiclassifierset |
| assessment_aigradingworkflow |
| assessment_aitrainingworkflow |
| assessment_aitrainingworkflow_training_examples |
| assessment_assessment |
| assessment_assessmentfeedback |
| assessment_assessmentfeedback_assessments |
| assessment_assessmentfeedback_options |
| assessment_assessmentfeedbackoption |
| assessment_assessmentpart |
| assessment_criterion |
| assessment_criterionoption |
| assessment_peerworkflow |
| assessment_peerworkflowitem |
| assessment_rubric |
| assessment_staffworkflow |
| assessment_studenttrainingworkflow |
| assessment_studenttrainingworkflowitem |
| assessment_trainingexample |
| assessment_trainingexample_options_selected |
| auth_group |
| auth_group_permissions |
| auth_permission |
| auth_registration |
| auth_user |
| auth_user_groups |
| auth_user_user_permissions |
| auth_userprofile |
| badges_badgeassertion |
| badges_badgeclass |
| badges_coursecompleteimageconfiguration |
| badges_courseeventbadgesconfiguration |
| block_structure |
| block_structure_config |
| bookmarks_bookmark |
| bookmarks_xblockcache |
| branding_brandingapiconfig |
| branding_brandinginfoconfig |
| bulk_email_bulkemailflag |
| bulk_email_cohorttarget |
| bulk_email_courseauthorization |
| bulk_email_courseemail |
| bulk_email_courseemail_targets |
| bulk_email_courseemailtemplate |
| bulk_email_coursemodetarget |
| bulk_email_optout |
| bulk_email_target |
| catalog_catalogintegration |
| celery_taskmeta |
| celery_tasksetmeta |
| celery_utils_chorddata |
| celery_utils_chorddata_completed_results |
| celery_utils_failedtask |
| certificates_certificategenerationconfiguration |
| certificates_certificategenerationcoursesetting |
| certificates_certificategenerationhistory |
| certificates_certificatehtmlviewconfiguration |
| certificates_certificateinvalidation |
| certificates_certificatetemplate |
| certificates_certificatetemplateasset |
| certificates_certificatewhitelist |
| certificates_examplecertificate |
| certificates_examplecertificateset |
| certificates_generatedcertificate |
| commerce_commerceconfiguration |
| contentserver_cdnuseragentsconfig |
| contentserver_courseassetcachettlconfig |
| contentstore_pushnotificationconfig |
| contentstore_videouploadconfig |
| cors_csrf_xdomainproxyconfiguration |
| corsheaders_corsmodel |
| course_action_state_coursererunstate |
| course_creators_coursecreator |
| course_groups_cohortmembership |
| course_groups_coursecohort |
| course_groups_coursecohortssettings |
| course_groups_courseusergroup |
| course_groups_courseusergroup_users |
| course_groups_courseusergrouppartitiongroup |
| course_groups_unregisteredlearnercohortassignments |
| course_modes_coursemode |
| course_modes_coursemodeexpirationconfig |
| course_modes_coursemodesarchive |
| course_overviews_courseoverview |
| course_overviews_courseoverviewimageconfig |
| course_overviews_courseoverviewimageset |
| course_overviews_courseoverviewtab |
| course_structures_coursestructure |
| courseware_offlinecomputedgrade |
| courseware_offlinecomputedgradelog |
| courseware_studentfieldoverride |
| courseware_studentmodule |
| courseware_studentmodulehistory |
| courseware_xmodulestudentinfofield |
| courseware_xmodulestudentprefsfield |
| courseware_xmoduleuserstatesummaryfield |
| crawlers_crawlersconfig |
| credentials_credentialsapiconfig |
| credit_creditconfig |
| credit_creditcourse |
| credit_crediteligibility |
| credit_creditprovider |
| credit_creditrequest |
| credit_creditrequirement |
| credit_creditrequirementstatus |
| credit_historicalcreditrequest |
| credit_historicalcreditrequirementstatus |
| dark_lang_darklangconfig |
| django_admin_log |
| django_comment_client_permission |
| django_comment_client_permission_roles |
| django_comment_client_role |
| django_comment_client_role_users |
| django_comment_common_coursediscussionsettings |
| django_comment_common_forumsconfig |
| django_content_type |
| django_migrations |
| django_openid_auth_association |
| django_openid_auth_nonce |
| django_openid_auth_useropenid |
| django_redirect |
| django_session |
| django_site |
| djcelery_crontabschedule |
| djcelery_intervalschedule |
| djcelery_periodictask |
| djcelery_periodictasks |
| djcelery_taskstate |
| djcelery_workerstate |
| edxval_coursevideo |
| edxval_encodedvideo |
| edxval_profile |
| edxval_subtitle |
| edxval_video |
| email_marketing_emailmarketingconfiguration |
| embargo_country |
| embargo_countryaccessrule |
| embargo_courseaccessrulehistory |
| embargo_embargoedcourse |
| embargo_embargoedstate |
| embargo_ipfilter |
| embargo_restrictedcourse |
| enterprise_enrollmentnotificationemailtemplate |
| enterprise_enterprisecourseenrollment |
| enterprise_enterprisecustomer |
| enterprise_enterprisecustomerbrandingconfiguration |
| enterprise_enterprisecustomerentitlement |
| enterprise_enterprisecustomeridentityprovider |
| enterprise_enterprisecustomeruser |
| enterprise_historicalenrollmentnotificationemailtemplate |
| enterprise_historicalenterprisecourseenrollment |
| enterprise_historicalenterprisecustomer |
| enterprise_historicalenterprisecustomerentitlement |
| enterprise_historicaluserdatasharingconsentaudit |
| enterprise_pendingenrollment |
| enterprise_pendingenterprisecustomeruser |
| enterprise_userdatasharingconsentaudit |
| experiments_experimentdata |
| experiments_experimentkeyvalue |
| external_auth_externalauthmap |
| grades_computegradessetting |
| grades_coursepersistentgradesflag |
| grades_persistentcoursegrade |
| grades_persistentgradesenabledflag |
| grades_persistentsubsectiongrade |
| grades_visibleblocks |
| instructor_task_gradereportsetting |
| instructor_task_instructortask |
| integrated_channel_enterpriseintegratedchannel |
| lms_xblock_xblockasidesconfig |
| microsite_configuration_historicalmicrositeorganizationmapping |
| microsite_configuration_historicalmicrositetemplate |
| microsite_configuration_microsite |
| microsite_configuration_micrositehistory |
| microsite_configuration_micrositeorganizationmapping |
| microsite_configuration_micrositetemplate |
| milestones_coursecontentmilestone |
| milestones_coursemilestone |
| milestones_milestone |
| milestones_milestonerelationshiptype |
| milestones_usermilestone |
| mobile_api_appversionconfig |
| mobile_api_ignoremobileavailableflagconfig |
| mobile_api_mobileapiconfig |
| notes_note |
| notify_notification |
| notify_notificationtype |
| notify_settings |
| notify_subscription |
| oauth2_accesstoken |
| oauth2_client |
| oauth2_grant |
| oauth2_provider_accesstoken |
| oauth2_provider_application |
| oauth2_provider_grant |
| oauth2_provider_refreshtoken |
| oauth2_provider_trustedclient |
| oauth2_refreshtoken |
| oauth_dispatch_restrictedapplication |
| oauth_provider_consumer |
| oauth_provider_nonce |
| oauth_provider_scope |
| oauth_provider_token |
| organizations_organization |
| organizations_organizationcourse |
| proctoring_proctoredexam |
| proctoring_proctoredexamreviewpolicy |
| proctoring_proctoredexamreviewpolicyhistory |
| proctoring_proctoredexamsoftwaresecurereview |
| proctoring_proctoredexamsoftwaresecurereviewhistory |
| proctoring_proctoredexamstudentallowance |
| proctoring_proctoredexamstudentallowancehistory |
| proctoring_proctoredexamstudentattempt |
| proctoring_proctoredexamstudentattemptcomment |
| proctoring_proctoredexamstudentattempthistory |
| programs_programsapiconfig |
| rss_proxy_whitelistedrssurl |
| sap_success_factors_catalogtransmissionaudit |
| sap_success_factors_historicalsapsuccessfactorsenterprisecus80ad |
| sap_success_factors_learnerdatatransmissionaudit |
| sap_success_factors_sapsuccessfactorsenterprisecustomerconfidb8a |
| sap_success_factors_sapsuccessfactorsglobalconfiguration |
| self_paced_selfpacedconfiguration |
| shoppingcart_certificateitem |
| shoppingcart_coupon |
| shoppingcart_couponredemption |
| shoppingcart_courseregcodeitem |
| shoppingcart_courseregcodeitemannotation |
| shoppingcart_courseregistrationcode |
| shoppingcart_courseregistrationcodeinvoiceitem |
| shoppingcart_donation |
| shoppingcart_donationconfiguration |
| shoppingcart_invoice |
| shoppingcart_invoicehistory |
| shoppingcart_invoiceitem |
| shoppingcart_invoicetransaction |
| shoppingcart_order |
| shoppingcart_orderitem |
| shoppingcart_paidcourseregistration |
| shoppingcart_paidcourseregistrationannotation |
| shoppingcart_registrationcoderedemption |
| site_configuration_siteconfiguration |
| site_configuration_siteconfigurationhistory |
| social_auth_association |
| social_auth_code |
| social_auth_nonce |
| social_auth_partial |
| social_auth_usersocialauth |
| splash_splashconfig |
| static_replace_assetbaseurlconfig |
| static_replace_assetexcludedextensionsconfig |
| status_coursemessage |
| status_globalstatusmessage |
| student_anonymoususerid |
| student_courseaccessrole |
| student_courseenrollment |
| student_courseenrollmentallowed |
| student_courseenrollmentattribute |
| student_dashboardconfiguration |
| student_enrollmentrefundconfiguration |
| student_entranceexamconfiguration |
| student_historicalcourseenrollment |
| student_languageproficiency |
| student_linkedinaddtoprofileconfiguration |
| student_loginfailures |
| student_logoutviewconfiguration |
| student_manualenrollmentaudit |
| student_passwordhistory |
| student_pendingemailchange |
| student_pendingnamechange |
| student_registrationcookieconfiguration |
| student_userattribute |
| student_usersignupsource |
| student_userstanding |
| student_usertestgroup |
| student_usertestgroup_users |
| submissions_score |
| submissions_scoreannotation |
| submissions_scoresummary |
| submissions_studentitem |
| submissions_submission |
| survey_surveyanswer |
| survey_surveyform |
| tagging_tagavailablevalues |
| tagging_tagcategories |
| teams_courseteam |
| teams_courseteammembership |
| theming_sitetheme |
| third_party_auth_ltiproviderconfig |
| third_party_auth_oauth2providerconfig |
| third_party_auth_providerapipermissions |
| third_party_auth_samlconfiguration |
| third_party_auth_samlproviderconfig |
| third_party_auth_samlproviderdata |
| thumbnail_kvstore |
| track_trackinglog |
| user_api_usercoursetag |
| user_api_userorgtag |
| user_api_userpreference |
| user_tasks_usertaskartifact |
| user_tasks_usertaskstatus |
| util_ratelimitconfiguration |
| verified_track_content_verifiedtrackcohortedcourse |
| verify_student_historicalverificationdeadline |
| verify_student_icrvstatusemailsconfiguration |
| verify_student_incoursereverificationconfiguration |
| verify_student_skippedreverification |
| verify_student_softwaresecurephotoverification |
| verify_student_verificationcheckpoint |
| verify_student_verificationcheckpoint_photo_verification |
| verify_student_verificationdeadline |
| verify_student_verificationstatus |
| video_config_coursehlsplaybackenabledflag |
| video_config_hlsplaybackenabledflag |
| waffle_flag |
| waffle_flag_groups |
| waffle_flag_users |
| waffle_sample |
| waffle_switch |
| waffle_utils_waffleflagcourseoverridemodel |
| wiki_article |
| wiki_articleforobject |
| wiki_articleplugin |
| wiki_articlerevision |
| wiki_attachment |
| wiki_attachmentrevision |
| wiki_image |
| wiki_imagerevision |
| wiki_reusableplugin |
| wiki_reusableplugin_articles |
| wiki_revisionplugin |
| wiki_revisionpluginrevision |
| wiki_simpleplugin |
| wiki_urlpath |
| workflow_assessmentworkflow |
| workflow_assessmentworkflowcancellation |
| workflow_assessmentworkflowstep |
| xblock_config_courseeditltifieldsenabledflag |
| xblock_config_studioconfig |
| xblock_django_xblockconfiguration |
| xblock_django_xblockstudioconfiguration |
| xblock_django_xblockstudioconfigurationflag |
+------------------------------------------------------------------+
346 rows in set (0.00 sec)
I have solv this problem!
This is the resource for all countries on openedx /edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django_countries/data.py
You need to restart your services after this action.
Good Luck!
i have database scheme like this.
# periode
+------+--------------+--------------+
| id | from | to |
+------+--------------+--------------+
| 1 | 2018-04-12 | 2018-05-11 |
| 2 | 2018-05-12 | 2018-06-11 |
+------+--------------+--------------+
# foo
+------+---------+
| id | name |
+------+---------+
| 1 | John |
| 2 | Doe |
| 3 | Trodi |
| 4 | son |
| 5 | Alex |
+------+---------+
#bar
+------+---------------+--------------+
| id | employee_id | periode_id |
+------+---------------+--------------+
| 1 | 1 |1 |
| 2 | 2 |1 |
| 3 | 1 |2 |
| 4 | 3 |1 |
+------+---------------+--------------+
I need to show employee that not in salary.
for now I do like this
queryset=Bar.objects.all().filter(periode_id=1)
result=Foo.objects.exclude(id=queryset)
but its fail, how do filter employee list not in salary?...
Well here you basically want the foos such that there is no period_id=1 in the Bar table.
We can let this work with:
ex = Bar.objects.all().filter(periode_id=1).values_list('employee_id', flat=True)
result=Foo.objects.exclude(id__in=ex)
I am using the following code to delete some rows from a dataset on a certain condition:
data MK_RETURN;
/*delete some data to solve the beta zero problem*/
if CUM_RETURN<RMIN then delete;
run;
However, I found out that the dataset MK_RETURN became not only empty, but also missing all the variables but CUM_RETURN and return.
Before the delete operation, the dataset contains six ~ seven variables. But after the delete operation, the dataset only contains two (empty variables), i.e. CUM_RETURN, RMIN.
What is wrong here?
The input data is something like
+--------+----------+------+--------------+--------------+-------------+----------+----------------+
| SYMBOL | DATE | time | CUM_RETURN | return_sec | RMIN | one_M | MK_RETURN_RATE |
+--------+----------+------+--------------+--------------+-------------+----------+----------------+
| A | 20130108 | 1 | 0 | | 0.00023571 | 1.90E-11 | 3.130243764 |
| A | 20130108 | 2 | | -0.00117855 | 0.000235988 | 1.90E-11 | 0.000274509 |
| A | 20130108 | 3 | 0.000471976 | 0.000471976 | 0.000235877 | 1.90E-11 | 6.86083E-05 |
| A | 20130108 | 4 | | -0.000471754 | 0.000235988 | 1.90E-11 | 6.86036E-05 |
| A | 20130108 | 5 | -0.000471976 | -0.000943953 | 0.000236211 | 1.90E-11 | 6.85989E-05 |
| A | 20130108 | 6 | | -0.002362112 | 0.000236771 | 1.90E-11 | 0 |
| A | 20130108 | 7 | 0.000711876 | 0.001183852 | 0.000236491 | 1.90E-11 | -0.000137188 |
| A | 20130108 | 8 | | 0.001300698 | 0.000236183 | 1.90E-11 | 0 |
| A | 20130108 | 9 | 0.000711876 | 0 | 0.000236183 | 1.90E-11 | 0 |
| A | 20130108 | 10 | | 0 | 0.000236183 | 1.90E-11 | 0.000137207 |
| A | 20130108 | 11 | 0.000711876 | 0 | 0.000236183 | 1.90E-11 | 0.000137188 |
| A | 20130108 | 12 | | 0.000590458 | 0.000236044 | 1.90E-11 | 6.85848E-05 |
| A | 20130108 | 13 | 0.000711876 | 0 | 0.000236044 | 1.90E-11 | 0 |
| A | 20130108 | 14 | | -0.000118022 | 0.000236072 | 1.90E-11 | -0.0003429 |
| A | 20130108 | 15 | 0.000711876 | 0 | 0.000236072 | 1.90E-11 | -0.000068604 |
+--------+----------+------+--------------+--------------+-------------+----------+----------------+
You didn't declare an input dataset (no set statement) - so you have created a new, empty dataset called MK_RETURN with two variables that were assigned as missing numerics given the absence of a definition.
Try the following (if not too late):
data MK_RETURN;
set INPUTDATASET; /* THIS is the line you need */
/*delete some data to solve the beta zero problem*/
if CUM_RETURN<RMIN then delete;
run;
I was trying to use the following code to do calculate cumulative return ():
retain MIDPRICE CUM_RETURN;
LAG_MIDPRICE = lag(MIDPRICE);
LAG_CUMRETURN = lag(CUM_RETURN);
return_sec = (MIDPRICE - LAG_MIDPRICE) / LAG_MIDPRICE;
if first.symbol then CUM_RETURN = 0;
else CUM_RETURN = return_sec + LAG_CUMRETURN;
However, with the if and else statement, the SAS is skipping a row:
+--------+----------+------+--------------+--------------+-------------+----------+----------------+
| SYMBOL | DATE | time | CUM_RETURN | return_sec | RMIN | one_M | MK_RETURN_RATE |
+--------+----------+------+--------------+--------------+-------------+----------+----------------+
| A | 20130108 | 1 | 0 | | 0.00023571 | 1.90E-11 | 3.130243764 |
| A | 20130108 | 2 | | -0.00117855 | 0.000235988 | 1.90E-11 | 0.000274509 |
| A | 20130108 | 3 | 0.000471976 | 0.000471976 | 0.000235877 | 1.90E-11 | 6.86083E-05 |
| A | 20130108 | 4 | | -0.000471754 | 0.000235988 | 1.90E-11 | 6.86036E-05 |
| A | 20130108 | 5 | -0.000471976 | -0.000943953 | 0.000236211 | 1.90E-11 | 6.85989E-05 |
| A | 20130108 | 6 | | -0.002362112 | 0.000236771 | 1.90E-11 | 0 |
| A | 20130108 | 7 | 0.000711876 | 0.001183852 | 0.000236491 | 1.90E-11 | -0.000137188 |
| A | 20130108 | 8 | | 0.001300698 | 0.000236183 | 1.90E-11 | 0 |
| A | 20130108 | 9 | 0.000711876 | 0 | 0.000236183 | 1.90E-11 | 0 |
| A | 20130108 | 10 | | 0 | 0.000236183 | 1.90E-11 | 0.000137207 |
| A | 20130108 | 11 | 0.000711876 | 0 | 0.000236183 | 1.90E-11 | 0.000137188 |
| A | 20130108 | 12 | | 0.000590458 | 0.000236044 | 1.90E-11 | 6.85848E-05 |
| A | 20130108 | 13 | 0.000711876 | 0 | 0.000236044 | 1.90E-11 | 0 |
| A | 20130108 | 14 | | -0.000118022 | 0.000236072 | 1.90E-11 | -0.0003429 |
| A | 20130108 | 15 | 0.000711876 | 0 | 0.000236072 | 1.90E-11 | -0.000068604 |
+--------+----------+------+--------------+--------------+-------------+----------+----------------+
As you can see, I want CUM_RETURN = return_sec + lag(CUM_RETURN), but it seems that now it is doing CUM_RETURN = return_sec + lag(lag(CUM_RETURN)).
I am aware of the issue that you cannot write lag directly in if and else conditions, that is why i used a LAG variable before the if else condition. But it seems that it is still working in a weird way ...
Besides, if i delete the if statement and do
if first.symbol then CUM_RETURN = 0;
CUM_RETURN = return_sec + LAG_CUMRETURN;
The entire column of CUM_RETURN just becomes empty ...
I don't think you need LAG_CUMRETURN, you have CUMRETURN in a retain.
(throwing out the other noise)
retain cumreturn;
if first.symbol then cumreturn = 0;
cumreturn = sum(cumreturn,return_sec);
That should get you what you want. The SUM() function treats a missing value as a 0, so for the first record of each security, CUMRETURN will stay 0.